I had broken my mind with JOLT. I need to group by data[].key then transform array in each group to object.
I had source JSON
{
"status": "OK",
"data": [
{
"value": 1,
"key": "John",
"subKey": "1W"
},
{
"value": 1,
"key": "John",
"subKey": "3W"
},
{
"value": 2,
"key": "John",
"subKey": "2W"
},
{
"value": 4,
"key": "John",
"subKey": "older"
},
{
"value": 5,
"key": "Tharanya",
"subKey": "2W"
},
{
"value": 5,
"key": "Tharanya",
"subKey": "1W"
}
]
}
Desired result is:
{
"status": "OK",
"data": [
{
"user": "John",
"1W": 1,
"2W": 2,
"3W": 1,
"older": 4
},
{
"user": "Tharanya",
"2W": 5,
"1W": 5
}
]
}
This transformation aggregates flat-list to map
[
{
"operation": "shift",
"spec": {
"data": {
"*": {
"@": "data.@(1,key)"
}
}
}
}
]
This one transform array to object
[
{
"operation": "shift",
"spec": {
"*": {
"value": "@(1,subKey)"
}
}
}
]
I need help to combine this transformation to chain. Thank you.