Anand Narayanan
Anand Narayanan

Reputation: 11

JOLT Transformation Needed for removing the element from array of JSON

I am trying remove a field from array of JSON using JOLT Transformation. below is the input JSON and expected output JSON.
can you suggest the JOLT transformation for the mentioned scenario

Input JSON

{
  "Actual": [
    {
      "properties": {
        "storeId": "newton_stores",
        "bulkDiscountDisplayedEvents": null
      },
      "Field_to_Delete": "Y"
    },
    {
      "properties": {
        "finalReceipt": {
          "totalAmount": "708.5",
          "totalDiscount": "67.9",
          "multiOfferEvents": [],
          "bulkDiscountDisplayedEvents": []
        }
      },
      "Field_to_Delete": "Y"
    }
  ]
}

expected Output

{
  "Actual": [
    {
      "properties": {
        "storeId": "newton_stores",
        "bulkDiscountDisplayedEvents": null
      }
    },
    {
      "properties": {
        "finalReceipt": {
          "totalAmount": "708.5",
          "totalDiscount": "67.9",
          "multiOfferEvents": [],
          "bulkDiscountDisplayedEvents": []
        }
      }
    }
  ]
}

Upvotes: 1

Views: 3934

Answers (1)

Barbaros Özhan
Barbaros Özhan

Reputation: 65323

You can use remove spec while looping through the sub-elements of the Actual array such as

[
  {
    "operation": "remove",
    "spec": {
      "Actual": {
        "*": {
          "Field_to_Delete": ""
        }
      }
    }
  }
]

where * wilcard represents the indexes of the array.

Upvotes: 1

Related Questions