Support Questions

Find answers, ask questions, and share your expertise

JOLT transformation

New Contributor

My input comes with pagination details, and I am able to get below using JOLT:

{
"0" : {
"key1": "value1"
"key2": "value2"
},
"1" : {
"key1": "value3"
"key2": "value4"
},
"2" : {
"key1": "value5"
"key2": "value6"
}
}

 

But my target is some thing like below:[
{
"key1": "value1",
"key2": "value2"
},
{
"key1": "value3",
"key2": "value4"
},
{
"key1": "value5",
"key2": "value6"
}
]

1 REPLY 1

Contributor

Hi @amitj1jan 
Spec:

[
{
"operation": "shift",
"spec": {
"*": "[]"
}
}
]

 I am here trying to iterate through every key of the input json at the root, i.e., * takes valules "0","1","2",... Now, I am taking the entire content at every iteration and pushing it to the empty array.
When * points to 0, Entire value inside "0" will be appended into empty array. Next, when * points to 1,entire content inside "1" will be added into the same array. Similarly for the remaining.
But, if the input is not in order and you want 6th(say) element to be inserted at 6th position of output, try the following spec:
[
  {
    "operation": "shift",
    "spec": {
      "*": "[&]"
    }
  }
]


Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.