1

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

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55

1 Answers1

0

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

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55