Home > Mobile >  Convert flat json to nested json using jolt transform
Convert flat json to nested json using jolt transform

Time:03-09

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.

CodePudding user response:

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 enter image description here

  • Related