Search code examples
jsonjolt

Need condition based jolt spec (if/else)


Need a jolt spec where body.Contract.stayRestrictions[].restrictionType="ClosedToArrival"

populate body.Block.stayRestrictions[].isClosedToArrival=true else populate false

input JSON :

{
  "body": {
    "Contract": {
      "stayRestrictions": [
        {
          "restrictionType": "ClosedToArrival"
        }
      ]
    }
  }
}

output JSON:

{
  "body": {
    "Block": {
      "stayRestriction": [
        {
          "isClosedToArrival": "true"
        }
      ]
    }
  }
}

Solution

  • You can use the conditional logic under "restrictionType" object within the following spec such as

    [
      {
        "operation": "shift",
        "spec": {
          "body": {
            "Contract": {
              "stayRestrictions": {
                "*": {
                  "restrictionType": {
                    "ClosedToArrival": {
                      "#true": "&6.&5.&4[&3].is&1"
                    },
                    "*": {//else case
                      "#false": "&6.&5.&4[&3].is&1"
                    }
                  }
                }
              }
            }
          }
        }
      }
    ]