Search code examples
jsonapache-nifijolt

Convert flat json to nested json using jolt transform


The input json :

{
  "key1": "value1",
  "key2": "value2",
  "key3": "value3",
  "key4": "value4"
}

The expected output:

{
  "key1" : "value1",
  "Name" : {
    "key2" : "value2",
    "key3" : "value3",
    "key4" : "value4"
  }
}

I would like to have a jolt transform, which can nest few fields.


Solution

  • You just need a shift transformation with a conditional logic: picking key1 and the rest of the attributes("*") such as

    [
      {
        "operation": "shift",
        "spec": {
          "key1": "&",
          "*": "Name.&"
        }
      }
    ]
    

    the demo on the site http://jolt-demo.appspot.com/

    enter image description here