Open Tokolosk opened 3 years ago
Spec:
[
{
"operation": "shift",
"spec": {
"*": {
"site_id": {
"*": {
"@2": "&[]"
}
}
}
}
}, {
"operation": "shift",
"spec": {
"*": {
"*": {
"site_id|site_name": "[#3].&0[]",
"*": "[#3].meters[#2].&0"
}
}
}
}, {
"operation": "shift",
"spec": {
"*": {
"meters": {
"*": {
"meter_id": {
"*": {
"@2": "[&5].meters.&[]"
}
}
}
},
"*": "[&1].&0"
}
}
}, {
"operation": "shift",
"spec": {
"*": {
"meters": {
"*": {
"*": {
"meter_id|meter_name": "[&4].meters[#3].&0[]",
"*": "[&4].meters[#3].meter_data[#2].&0"
}
}
},
"*": "[&1].&0"
}
}
}, {
"operation": "cardinality",
"spec": {
"*": {
"site_name": "ONE",
"site_id": "ONE",
"meters": {
"*": {
"meter_name": "ONE",
"meter_id": "ONE"
}
}
}
}
}
]
I'm trying to convert this json with Jolt, from a flat structure to a nested structure.
The key point here is that a "site" has a whole lot of meters in an array, and a "meter" has a whole lot of data in an array. I've cleaned it up here to show fewer objects per array but the idea is that there can be many.
My main difficulty is merging all the meters that belong to site1 under an array for site1 and not a bunch of site1 arrays.
Input:
Desired output: