Skip to main content
gcunha
Gold ⭐️
Aug 29, 2018 3:24 PM UTC

Using JOLT to modify JSON Object

  • Oct 5, 2026 9:06 AM UTC
  • 0 replies
  • 8490 views
  • Translate All

Short Description:

Using JOLT transformation to modify a JSON object.

Article:

In NIFI, JOLT Transformation can be used to help modifying a JSON object, the below code snippets are an example of how JOLT can be used to shift elements inside a JSON Object, in this case, the intention is to move and repeat "productionID" and "processID" inside of the array.

Original JSON Object:

{
"productionID": "BHS0928MDB8391",
"productionLine": [
{
"model": "Cooper",
"year": 2018,
"type": "Hatchback",
"motorization": "Electric",
"colour": "Midnight Black",
"stageID": "MGOP94810482042"
},
{
"model": "Cooper",
"year": 2018,
"type": "Hatchback",
"motorization": "Diesel",
"colour": "Silver",
"stageID": "MGOP9183740194"
}
],
"processID": "884910421743POR4183UK"
}

Target JSON Object:

{
"productionLine" : [ {
"model" : "Cooper",
"year" : 2018,
"type" : "Hatchback",
"motorization" : "Electric",
"colour" : "Midnight Black",
"stageID" : "MGOP94810482042",
"productionID" : "BHS0928MDB8391",
"processID" : "884910421743POR4183UK"
}, {
"model" : "Cooper",
"year" : 2018,
"type" : "Hatchback",
"motorization" : "Diesel",
"colour" : "Silver",
"stageID" : "MGOP9183740194",
"productionID" : "BHS0928MDB8391",
"processID" : "884910421743POR4183UK"
} ]
}

JOLT transformation code used:

[
{
"operation": "shift",
"spec": {
"productionLine": {
"*": {
"@": "[&1]",
"@(2,productionID)": "[&1].productionID",
"@(2,processID)": "[&1].processID"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"@": "productionLine"
}
}
}
]