Home > front end >  JOLT transform - Remove empty node in the JSON Array
JOLT transform - Remove empty node in the JSON Array

Time:07-29

Can someone help with Jolt spec for the below requirement? Input:

{
  "individuals": [
    {
      "individual": {
        "LastName": "Ind1-LastName",
        "firstName": "Ind1-FirstName"
      }
    },
    {
      "individual": {}
    }
  ]
}

Expected output:

{
  "linkedIndividuals": [
    {
      "individual": {
        "LastName": "Ind1-LastName",
        "firstName": "Ind1-FirstName"
      }
    }
  ]
}

CodePudding user response:

You can dive deep upto the innermost node in order to encounter the key name without a value, then add the respective replacement symbols(&3.[&2].&1.&) consecutively to construct the JSON body again by using such a shift transformation spec such as

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "*": "linked&3.[&2].&1.&"
          }
        }
      }
    }
  }
]

the demo on the site enter image description here

  • Related