Search code examples
javaarraysjsondataframejolt

JOLT Remove based on value and keep rest of the json keys


Below is my JSON and i need JOLT to remove if destSiteName is unknown. Need to keep the rest of the object.

{
  "destSiteName": "unknown",
  "customer_code": "code1"
}

Solution

  • You might use a shift transformation which contains two conditionals

    • whether outermost attribute is "destSiteName" or not ( "*" )

    or

    • whether value of "destSiteName" is "unknown" or not ( "*" )
    [
      {
        "operation": "shift",
        "spec": {
          "destSiteName": {
            "unknown": "",
            "*": { "@1": "&2" }
          },
          "*": "&"
        }
      }
    ]