I am having trouble getting the desired Output using Jolt Transform.
My input JsonArray looks like this:
[
{
"from": [
{
"area1": 1
},
{
"area2": 1
},
{
"area3": 1
}
],
"id": 111,
"to": "destination1"
},
{
"from": [
{
"area1": 2
},
{
"area2": 2
},
{
"area3": 2
}
],
"id": 222,
"to": "destination2"
}
]
I am using this Jolt Spec to create a JsonArray for every JsonObject in the JsonArray "from" and want to include the where "id" and "to" keys:
[
{
"operation": "shift",
"spec": {
"*": {
"from": {
"*": {
"@": "[&]",
"@(2,id)": "[&].id",
"@(2,to)": "[&].to"
}
}
}
}
}
]
This is the output:
[
[
{
"area1": 1,
"id": 111,
"to": "destination1"
},
{
"area1": 2
}
],
[
{
"area2": 1,
"id": 111,
"to": "destination1"
},
{
"area2": 2
}
],
[
{
"area3": 1,
"id": 111,
"to": "destination1"
},
{
"area3": 2
}
]
]
My desired output would look something like that:
[
{
"area1": 1,
"id": 111,
"to": "destination1"
},
{
"area1": 2,
"id": 222,
"to": "destination2"
},
{
"area2": 1,
"id": 111,
"to": "destination1"
},
{
"area2": 2,
"id": 222,
"to": "destination2"
},
{
"area3": 1,
"id": 111,
"to": "destination1"
},
{
"area3": 2,
"id": 222,
"to": "destination2"
}
]
I am not sure, why the "id" and "to" key aren't included from the second JSON Object of the input. Does anyone know how to fix the Jolt to get the desiered output?
First of all, no need to write the outer attributes one by one
I'd suggest the following shift as the first spec, If there was only one nested object within the outermost array :
but because you have twice, then need to separate them, to do this : Prefix the identifiers by &4 and &3 respectively as in the following complete transformation :
the demo on the site https://jolt-demo.appspot.com/ is :