bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.54k stars 328 forks source link

Conditioinal rendering #1190

Open Diptesh14 opened 1 year ago

Diptesh14 commented 1 year ago

Hi, I need a help on the following transformation input: "Address": [ { "AddressLine1Tx": "GORDON ROAD", "CurrentPrevious": "Current", "UnstrdPostalAddrssTypeCd": "null" }, { "AddressLine1Tx": "11600 Hidden Grove Trail", "CurrentPrevious": "Previous", "UnstrdPostalAddrssTypeCd": "null" } ]

Output:

{ "CurrentAddress": { "AddressLine1Tx": "GORDON ROAD", "UnstrdPostalAddrssTypeCd": "null" }, "PreviousAddress": { "AddressLine1Tx": "11600 Hidden Grove Trail", "UnstrdPostalAddrssTypeCd": "null" } }

gawhadebhavna commented 1 year ago

Hi @Diptesh14

You can use the below spec

[
  {
    "operation": "shift",
    "spec": {
      "Address": {
        "*": {
          "CurrentPrevious": {
            "Current": {
              "@2": "CurrentAddress"
            },
            "Previous": {
              "@2": "PreviousAddress"
            }
          }
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "*": {
        "CurrentPrevious": ""
      }
    }
  }
]