The JSON field uses to decide the value for another JSON field in Jolt

44 Views Asked by At

Let say we have on JSON

{
  "payments": [
    {
      "paymentId": "16493256102836651255",
      "amount": 9.26,
      "cardType": "DISC",
      "transactionType": "PAYPAL"
    }
  ]
}

expected :

{
  "payment": [
    {
      "paymentId": "16493256102836651255",
      "payment_type": "MTL",
      "transactionType": "REGULAR"
    }
  ]
}

I already tried with this spec

[
  {
    "operation": "shift",
    "spec": {
      "payments": {
        "*": {
          "cardType": {
            "LAR": {
              "#MTL": "payment.[].payment_type"
            }
          }
        }
      }
    }
  }
]

I have on more condition that if cardType type is LAR or transactionType is PAYPAL then is should map with MTL I am able to get the MTL if card type is LAR but need to check if LAR is not card type but transaction type is PAYPAL then also it should so MTL

1

There are 1 best solutions below

0
Barbaros Özhan On

You can use individual conditional as objects per each one (cardType and transactionType) such as

[
  {
    "operation": "shift",
    "spec": {
      "payments": {
        "*": {
          "paymentId": "payment[&1].&",
          "cardType": {
            "LAR": {
              "#MTL": "payment[&3].payment_type[]",
              "#REGULAR": "payment[&3].transactionType"
            }
          },
          "transactionType": {
            "PAYPAL": {
              "#MTL": "payment[&3].payment_type[]",
              "#REGULAR": "payment[&3].transactionType"
            }
          }
        }
      }
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "*": {
          "*": "ONE"
        }
      }
    }
  }
]

the demo on the site http://jolt-demo.appspot.com/ is

enter image description here