I have to transform one JSON to another JSON, I am new to jolt.if you have any other methods in java please let me know. Input can have many other attributes in a nested manner. I have to make generic code which can consume all the fields in JSON and transform it into the desired output which I have mentioned.
Input
{
"id": "123456789",
"OrderType": "ABC",
"Abc": [
{
"Name": "Pluto",
"Value": "Charon"
},
{
"Name": "Earth",
"Value": "Moon"
}
]
}
Desired Output
"MyFieldList": [
{
"Footer": "My Footer",
"fieldList": [
{
"label": "id",
"fieldName": "id",
"fieldValue": "123456789",
"editable": false,
"dataType": "STRING"
},
{
"label": "OrderType",
"fieldName": "OrderType",
"fieldValue": "ABC",
"editable": false,
"dataType": "STRING"
},
{
"label": "Pluto",
"fieldName": "Pluto",
"fieldValue": "Charon",
"editable": false,
"dataType": "STRING"
},
{
"label": "Earth",
"fieldName": "Earth",
"fieldValue": "Moon",
"editable": false,
"dataType": "STRING"
}]
}
]
I have tried using this jolt spec but , I cannot figure out the nested part how to flatten it .
{
"operation": "shift",
"spec": {
"*": {
"$": "[#2].fieldName",
"@": "[#2].fieldValue",
"#false": "[#2].editable",
"# ": "[#2].Size",
"#STRING": "[#2].dataType"
}
}
}