I am having trouble dealing with arrays in JOLT.
Input:
[
{
"id": "1",
"home_phone": [
"55555555",
"66666666"
]
},
{
"id": "2",
"home_phone": [
"77777777",
"88888888"
]
}
]
Desired output:
[
{
"id": "1",
"home": "55555555"
},
{
"id": "1",
"home": "66666666"
},
{
"id": "2",
"home_phone": "77777777"
},
{
"id": "2",
"home_phone": "88888888"
}
]
Note that each element of the home_phone array should be matched with its correspondent id in its JSON document.
This is the spec I have drafted so far without much success:
[
{
"operation": "shift",
"spec": {
"*": {
"home_phone": {
"*": "[].phone",
"@(1,id)": "[].id"
}
}
}
}
]
Any ideas? Thanks!
2
Answers
You can create your objects in an array of an array in one
shift
operation and then you can bring them up with just going to that level with"*": ""
in the secondshift
operation.One approach would be using