Closed bulletblp4 closed 5 years ago
You have to do two shift operations.
First one, is used to push the "id" field "down", maintaining the same "structure" of the input "domesticAnimals" and "cats" and "dogs" arrays.
The second shift, can then build the desired "cat" and "dogs" output arrays, by moving/accumulating the now "correct" "cat" and "dog" entries.
Spec
[
{
"operation": "shift",
"spec": {
"sanctuary": {
"*": {
"animals": {
"*": {
"domesticAnimals": {
"*": {
"cats": {
"*": {
"name": "temp[&3].cats[&1].name",
"@(2,id)": "temp[&3].cats[&1].id"
}
},
"dogs": {
"*": {
"name": "temp[&3].dogs[&1].name",
"food": "temp[&3].dogs[&1].food",
"@(2,id)": "temp[&3].dogs[&1].id"
}
}
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"temp": {
"*": {
"cats": {
"*": "pets[0].cats[]"
},
"dogs": {
"*": "pets[0].dogs[]"
}
}
}
}
}
]
Technically this can be "simplified" to this spec, but it is harder to tell what is going on. Spec
[
{
"operation": "shift",
"spec": {
"sanctuary": {
"*": {
"animals": {
"*": {
"domesticAnimals": {
"*": {
"cats|dogs": {
"*": {
"*": "temp[&3].&2[&1].&",
"@(2,id)": "temp[&3].&2[&1].id"
}
}
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"temp": {
"*": {
"*": {
"*": "pets[0].&1[]"
}
}
}
}
}
]
Thanks for your quick response.... That worked like magic.. Had never used |
operator before.
I am trying convert a multiple level lists to a list of list. The input object
domesticAnimals
has either thedog list
populate or thecat list
. I want to combine all dog type across all thedomesticAnimals array
in one list and similarly for cats. Since I am referencing to thedomesticAnimal
index it populates thepets[].dog[]
with 0th and 1st element as null. Is there an operator that would skip the null object, or is there any better way to handle this.spec
output
expected output