Home > Software engineering >  JSON object to array with JOLT
JSON object to array with JOLT

Time:01-19

I have the following JSON object

Input:

{
  "17.39.108.85:80": [],
  "10.204.32.9:443": [
    {
      "status": "DOWN"
    }
  ]
}

and trying to transform it into a list/array as below :

Desired Output:

[
  {
    "17.39.108.85:80": []
  },
  {
    "10.204.32.9:443": [
      {
        "status": "DOWN"
      }
    ]
  }
]

What's the best way to use Jolt.

CodePudding user response:

You can use this spec:

Currently, your input is correct, but you need to put each key into an array.

You can get each key in the object and send it to an array with [#2].

Note: #2 is the index of each key. for example: 17.39.108.85:80 is 0 and 10.204.32.9:443 is 1.

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "@": "[#2].&"
      }
    }
  }
]
  • Related