Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Community Articles

Find and share helpful community-sourced technical articles.
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!
Labels (1)
avatar
Rising Star

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"
      }
    }
  }
]

8,510 Views
Version history
Last update:
‎08-29-2018 08:24 AM
Updated by:
Contributors