Manan Kapoor
Manan Kapoor

Reputation: 677

How to get multiple array value as object

Hi I am new to JOLT transformation. I need to transform the input json using JOLT to get below seen output. Please help me in below transformation:

input:
  {
    "image": [
      "content1",
      "content2",
      "content3"
],
   "legal": [
      "legal1",
      "legal2",
      "legal3"
 ], 
"hyper": [
      "hyper1",
      "hyper2",
      "hyper3"
]
}

output:

[
{
   "image": "content1",
   "legal": "legal1",
   "hyper": "hyper1"
},
{
   "image": "content1",
   "legal": "legal1",
   "hyper": "hyper1"
},
{
   "image": "content1",
   "legal": "legal1",
   "hyper": "hyper1"
}
]

Upvotes: 0

Views: 277

Answers (1)

Milo S
Milo S

Reputation: 4586

Spec

[
  {
    "operation": "shift",
    "spec": {
      "*": { // image, legal, etc
        "*": { // array
          "*": { // content1, legal1, etc
            "$": "[&2].&3" // grab "content1" and use it as output
                 // send it to an output doc that is a top level array
                 // indexed by looking 3 levels up the tree [&2]
          }
        }
      }
    }
  }
]

Upvotes: 1

Related Questions