I’m currently trying to perform an operation in jolt that I believe would be easiest if I could group my data by a value first. I am trying to group this list by the value columnIndex
Input:
{
"temp_sfp": [
{
"value": 600,
"valueOperator": "=",
"uom": "mcg",
"name": "Vitamin D (as D3 Cholecalciferol)",
"percentDvOperator": "=",
"percentDv": "75.0",
"columnIndex": 1
},
{
"value": 2,
"valueOperator": "=",
"uom": null,
"name": "Bacillus Coagulans",
"percentDvOperator": "=",
"percentDv": null,
"columnIndex": 1
},
{
"value": 300,
"valueOperator": "=",
"uom": "mcg",
"name": "Vitamin D (as D3 Cholecalciferol)",
"percentDvOperator": "=",
"percentDv": "50.0",
"columnIndex": 0
},
{
"value": 1,
"valueOperator": "=",
"uom": "mg",
"name": "Bacillus Coagulans",
"percentDvOperator": "=",
"percentDv": null,
"columnIndex": 0
}
]
}
Desired Output:
{
"sfp_group": [
{
"1": [
{
"value": 600,
"valueOperator": "=",
"uom": "mcg",
"name": "Vitamin D (as D3 Cholecalciferol)",
"percentDvOperator": "=",
"percentDv": "75.0",
"columnIndex": 1
},
{
"value": 2,
"valueOperator": "=",
"uom": null,
"name": "Bacillus Coagulans",
"percentDvOperator": "=",
"percentDv": null,
"columnIndex": 1
}
]
},
{
"2": [
{
"value": 300,
"valueOperator": "=",
"uom": "mcg",
"name": "Vitamin D (as D3 Cholecalciferol)",
"percentDvOperator": "=",
"percentDv": "50.0",
"columnIndex": 0
},
{
"value": 1,
"valueOperator": "=",
"uom": "mg",
"name": "Bacillus Coagulans",
"percentDvOperator": "=",
"percentDv": null,
"columnIndex": 0
}
]
}
]
}
From previous posts I’ve tried something like this to try and group on column index
{
"operation": "shift",
"spec": {
"@1": "",
"temp_sfp": {
"*": {
"columnIndex": {
"*": {
"*": {
"@4": "&2"
}
}
}
}
}
}
}
but I can’t seem to really wrap my head around it.
2
Answers
The trick is to use
@1,columnIndex
on the right hand side, it’s suitable to duplicate them for your case.So, you can use the following shift transformation spec :
which will give the desired result if columnIndex values are 0,1 as in the current input, but if they are different such as 1,2 as stated within the desired output, then the following spec would be better to use(to be generic)
Alternative syntax 🙂