Options
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Rising Star
Created on 08-29-2018 08:24 AM
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" } } } ]
7,630 Views