I have this input JSON:
{
"people": [
{
"foo_name": "jack",
"id": 123,
"some_attr1": "val1"
},
{
"foo_name": "bob",
"id": 456,
"some_other_attr1": "val2"
},
{
"foo_name": "jack",
"cool_attr1": "val3",
"not_cool_attr1": "val4",
"some_attr1": "vvaaalllllll"
}
]
}
The desired output is:
{
"people": [
{
"foo_name": "jack",
"id": 123,
"some_attr1": "val1", // in case of common keys, grab the first one
"cool_attr1": "val3", // order of merged keys does not matter
"not_cool_attr1": "val4"
},
{
"foo_name": "bob",
"id": 456,
"some_other_attr1": "val2"
}
]
}
Where keys in the object "foo_name": "jack"
gets merged. Order of the keys does not matter. The value jack
is not known ahead of time.
What I tried so far:
[
{
"operation": "shift",
"spec": {
"people": { // only the people array
"*": { // foreach item
"foo_name": { // group by foo_name
"*": {
"@2": "&[]"
}
}
}
}
}
}
]
Similar questions:
2
Answers
This spec will do it. Need to
people
array byfoo_name
.cardinality
assigns ONE for every key.people
array.You can use the following transformation spec