Closed Chris-Fri closed 8 months ago
It's probably possible to reduce the number of jolt operations but it works.
[
{ // grouping by id
"operation": "shift",
"spec": {
"data": {
"designGeneral": {
"*": { // index array of designGeneral
"*": "data.designGeneral.@(1,id).@(1,designedFor.id).&",
"hasPart": {
"*": { // index array of hasPart
"*": "data.designGeneral.@(3,id).@(3,designedFor.id).hasPart.@(1,id).&"
}
}
}
}
}
}
},
{ // to array designGeneral (after grouping)
"operation": "shift",
"spec": {
"data": {
"designGeneral": {
"*": { // id
"*": "data.designGeneral[]"
}
}
}
}
},
{ // to array hasPart (after grouping)
"operation": "shift",
"spec": {
"data": {
"designGeneral": {
"*": { // index array
"*": "data.designGeneral[&1].&",
"hasPart": {
"*": "data.designGeneral[&2].&1[]"
}
}
}
}
}
},
{ // get only first element of id and designedFor (delete duplicate values)
"operation": "cardinality",
"spec": {
"data": {
"designGeneral": {
"*": { // index array
"id": "ONE",
"designedFor": "ONE"
}
}
}
}
}
]
That's great! Thanks a lot, @gbouget
I have the below json
and I would like to modify it to get the below json where the last 2 entries are merged as they have the same
But of course more generally the operation should transform any such json file and always merge the "hasPart" arrays where the "id" and "designedFor" of a "designGeneral" item is the same.