Search code examples
javaarraysjsonapache-nifijolt

Not able to Convert Array of Json to Flattern Json Using Jolt (V0.1.1)


Input payload:

{
  "accountNo":112233,
  "type":"DEDICATED",
  "Plans" : {
     "One":"Basic",
     "Two":"Mid",
     "Three":"Premium"  
   },

  "Address": {
     "Primary":{
       "Addressline1":" road 1, boss lane",
      "AddressLine2": "ST",
    "City":"Tex"
    }
  }

}

Expected PayLoad:

{
  "accountNo":112233,
  "type":"DEDICATED",
  "One":"Basic",
  "Two":"Mid",
  "Three":"Premium",
  "Addressline1":" road 1, boss lane",
  "AddressLine2": "ST",
  "City":"Tex"
}

Used Jolt v0.1.1 not able to convert , could anyone help me out


Solution

  • You can individually evaluate the expression by seperating into the conditional branches of Plans, Address.Primary and * for the rest(non-nested) of the elements within a shift transformation such as

    [
      {
        "operation": "shift",
        "spec": {
          "Plans": {
            "*": "&"
          },
          "Address": {
            "Primary": {
              "*": "&"
            }
          },
          "*": {
            "@": "&"
          }
        }
      }
    ]