Karthik
Karthik

Reputation: 21

Remove empty object in jolt

I have a JSON input :

{
  "partyContactList": [
    {
      "firstName": "r",
      "lastName": "g",
      "contactEnrichment": {}
    }
  ]
}

and expected one as follows :

{
  "partyContactList": [
    {
      "firstName": "r",
      "lastName": "g",
    }
  ]
}

where I'm trying to remove from Jolt transformation contactEnrichment : {} , eg. Remove contact enrichment as its empty object.

Upvotes: 0

Views: 38

Answers (1)

Barbaros Özhan
Barbaros Özhan

Reputation: 65323

You can use the following shift transformation spec :

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": "&2[&1].&",
          "contactEnrichment": {
            "*": "&3[&2].&1.&",
            "": ""//an empty value matches another empty value whenever there's no comtent
          }
        }
      }
    }
  }
]

Upvotes: 0

Related Questions