0

I have following JSON structure

{
    "customFields": {
        "paymentMethods": [
            {
                "tokenizedCard": "11223",
                "cardNumber": "XXXXXX001"
            },
            {
                "tokenizedCard": "12345",
                "cardNumber": "XXXXX678"
            }
        ]
    },
    "paymentDetails": {
        "method": [
            {
                "paymentType": "CREDIT_CARD",
                "tokenizedCard": "11223"
            },
            {
                "paymentType": "UPI",
                "tokenizedCard": "12345"
            }
        ]
    }
}

I want to validate this JSON with following condition.

If paymentDetails.method.paymentType = CREDIT_CARD then
    compare tokenizedCard from same object with the tokenizedCard of customFields.paymentMethods and if matches then make cardNumber required from that object of customFields.paymentMethods.

I tried using $ref & $definition and but I was not able to make that happen.

Any help with the required schema would be appreciated!

Note: I am doing schema validation in azure logic app.

PKH
  • 47
  • 1
  • 2
  • 6
  • You might want to show us your schema and what you’ve done. – Skin Apr 15 '23 at 21:21
  • Depending on what JSON Schema features Azure supports, you'll either want `if`/`then` or the Implication Pattern from https://stackoverflow.com/questions/38717933/jsonschema-attribute-conditionally-required – Jason Desrosiers Apr 17 '23 at 18:23

1 Answers1

0

Using variables and condition action, you can achieve the scenario.

I have reproduced issue from my side and below are steps I followed,

  • Created logic app as shown below, enter image description here
  • Passing the Json in Http request trigger as shown below, enter image description here
  • Initialized three variables for tokenizedCard of paymentDetails, tokenizedCard of paymentMethods and cardNumber of paymentMethods. enter image description here
  • Next taken a for each loop and passed input as triggerBody()?['paymentDetails']?['method'] enter image description here
  • Next taken a condition action and used expression items('For_each')?['paymentType'] is equal to CREDIT_CARD enter image description here
  • In true block added actions as shown below, enter image description here
  • For comparing tokenizedCard added another for each loop and passed input as triggerBody()?['customFields']?['paymentMethods']
  • Next set variable for tokenizedCard. One is for paymentDetails and other is for paymentMethods. enter image description here
  • Next taken another condition action to compare two tokenizedCards. enter image description here
  • If both are matching then getting card number value as shown below, enter image description here
  • Tested logic app and able to get card number, enter image description here

Output of getting card number: enter image description here

vijaya
  • 1,525
  • 1
  • 2
  • 6