Solved
Jolt Transformation (nested array modifications)
Hi everyone!
I hope all is well.
I have this json
{
"Data": {
"ID": "09878666",
"DATE": "2022-01-01",
"ARRAY_ONE": [
{
"NAME": "test_1",
"details": [
{
"address": "123123"
}
]
},
{
"NAME": "test_2",
"details": [
{
"address": "123123"
},
{
"address": "123123"
}
]
}
]
}
}
and I transformed the structure to this:
[
{
"ID": "09878666",
"DATE": "2022-01-01",
"NAME": "test_1",
"details": [
{
"address": "123123"
}
]
},
{
"ID": "09878666",
"DATE": "2022-01-01",
"NAME": "test_2",
"details": [
{
"address": "123123"
},
{
"address": "123123"
}
]
}
]
Which is perfect except for the inner arrays, I want to flatten the array to be like this
[
{
"ID": "09878666",
"DATE": "2022-01-01",
"NAME": "test_1",
"details_0_adrress":"123123"
},
{
"ID": "09878666",
"DATE": "2022-01-01",
"NAME": "test_2",
"details_0_adrress":"123123",
"details_1_adrress":"123123"
}
]
Here is my spec:
[
{
"operation": "shift",
"spec": {
"Data": {
"ARRAY_ONE": {
"*": {
"@(2,ID)": "[#2].ID",
"@(2,DATE)": "[#2].DATE",
"NAME": "[#2].NAME",
"details": "[#2].details"
}
}
}
}
}
]
I know how to flatten an array but I'm not sure how to do it using the current spec:,
What I would normally do is something like this:
{
"operation": "shift",
"spec": {
"details": {
"*": {
"address": "details_&1_address"
}
}
}
}
But it did not work so well.
Thank you!

