title: JsonSchema: Validate an item in the List based on value of another attribute
body: <p>I have a requirement to put a check on value based on certain other attribute value in same object (both of them are inside list ) e.g paymentType is SHOPPING_CARDS, I want to mandate few attributes i.e paymentReference1 , paymentReference2 otherwise not. I have added this check , I am passing paymentType as CASH but still getting false error that required attributes are missing , though paymentId1 is being passed in all the items in list. Can someone please help to find out what I am doing wrong?</p>
  <p><a href="https://www.jsonschemavalidator.net/s/1An8ooOQ" rel="nofollow noreferrer">Failing Impl</a></p>
  <p>Error
  $.paymentReference1: is missing but it is required</p>
  <p>Update- As per one comment below , I have moved if/else in schema where this check is required but now issue is it is not raising any alarm when we remove paymentRef.</p>
  <p>Json Schema</p>
  <pre><code>{
  &quot;type&quot;: &quot;object&quot;,
  &quot;required&quot;: [
   &quot;payment&quot;
   ],
  &quot;properties&quot;: {
  &quot;payment&quot;: {
    &quot;$id&quot;: &quot;#root/payment&quot;,
    &quot;title&quot;: &quot;Payment&quot;,
    &quot;type&quot;: &quot;object&quot;,
    &quot;required&quot;: [
      &quot;requestId&quot;,
      &quot;requestTimestamp&quot;,
      &quot;requestType&quot;,
      &quot;orderNo&quot;,
      &quot;orderDate&quot;,
      &quot;enterpriseCode&quot;,
      &quot;documentType&quot;,
      &quot;entryType&quot;,
      &quot;paymentRuleId&quot;,
      &quot;membershipNo&quot;,
      &quot;orderTotalAmount&quot;,
      &quot;priceInfo&quot;,
      &quot;paymentMethods&quot;,
      &quot;createServiceId&quot;
    ],
    &quot;properties&quot;: {
      &quot;requestId&quot;: {
        &quot;$id&quot;: &quot;#root/payment/requestId&quot;,
        &quot;title&quot;: &quot;Requestid&quot;,
        &quot;type&quot;: &quot;string&quot;,
        &quot;default&quot;: &quot;&quot;,
        &quot;examples&quot;: [
          &quot;263e9575-09ea-45dc-b1d9-87ec7888d3ff&quot;
        ],
        &quot;pattern&quot;: &quot;^.*$&quot;
      },
      &quot;requestTimestamp&quot;: {
        &quot;$id&quot;: &quot;#root/payment/requestTimestamp&quot;,
        &quot;title&quot;: &quot;Requesttimestamp&quot;,
        &quot;type&quot;: &quot;string&quot;,
        &quot;default&quot;: &quot;&quot;,
        &quot;examples&quot;: [
          &quot;2021-12-01T07:16:31Z&quot;
        ],
        &quot;pattern&quot;: &quot;^.*$&quot;
      },
      &quot;requestType&quot;: {
        &quot;$id&quot;: &quot;#root/payment/requestType&quot;,
        &quot;title&quot;: &quot;Requesttype&quot;,
        &quot;type&quot;: &quot;string&quot;,
        &quot;default&quot;: &quot;&quot;,
        &quot;examples&quot;: [
          &quot;CREATE_ORDER/ADDITION&quot;
        ],
        &quot;pattern&quot;: &quot;^.*$&quot;
      },
      &quot;orderNo&quot;: {
        &quot;$id&quot;: &quot;#root/payment/orderNo&quot;,
        &quot;title&quot;: &quot;Orderno&quot;,
        &quot;type&quot;: &quot;string&quot;,
        &quot;default&quot;: &quot;&quot;,
        &quot;examples&quot;: [
          &quot;9762909359&quot;
        ],
        &quot;pattern&quot;: &quot;^.*$&quot;
      },
      &quot;orderDate&quot;: {
        &quot;$id&quot;: &quot;#root/payment/orderDate&quot;,
        &quot;title&quot;: &quot;Orderdate&quot;,
        &quot;type&quot;: &quot;string&quot;,
        &quot;default&quot;: &quot;&quot;,
        &quot;examples&quot;: [
          &quot;2022-05-09T14:01:21.000+0000&quot;
        ],
        &quot;pattern&quot;: &quot;^.*$&quot;
      },
      &quot;enterpriseCode&quot;: {
        &quot;$id&quot;: &quot;#root/payment/enterpriseCode&quot;,
        &quot;title&quot;: &quot;Enterprisecode&quot;,
        &quot;type&quot;: &quot;string&quot;,
        &quot;default&quot;: &quot;&quot;,
        &quot;examples&quot;: [
          &quot;SAMS&quot;
        ],
        &quot;pattern&quot;: &quot;^.*$&quot;
      },
      &quot;documentType&quot;: {
        &quot;$id&quot;: &quot;#root/payment/documentType&quot;,
        &quot;title&quot;: &quot;Documenttype&quot;,
        &quot;type&quot;: &quot;string&quot;,
        &quot;default&quot;: &quot;&quot;,
        &quot;examples&quot;: [
          &quot;0001&quot;
        ],
        &quot;pattern&quot;: &quot;^.*$&quot;
      },
      &quot;entryType&quot;: {
        &quot;$id&quot;: &quot;#root/payment/entryType&quot;,
        &quot;title&quot;: &quot;Entrytype&quot;,
        &quot;type&quot;: &quot;string&quot;,
        &quot;default&quot;: &quot;&quot;,
        &quot;examples&quot;: [
          &quot;ONLINE&quot;
        ],
        &quot;pattern&quot;: &quot;^.*$&quot;
      },
      &quot;paymentRuleId&quot;: {
        &quot;$id&quot;: &quot;#root/payment/paymentRuleId&quot;,
        &quot;title&quot;: &quot;Paymentruleid&quot;,
        &quot;type&quot;: &quot;string&quot;,
        &quot;default&quot;: &quot;&quot;,
        &quot;examples&quot;: [
          &quot;SAMS&quot;
        ],
        &quot;pattern&quot;: &quot;^.*$&quot;
      },
      &quot;membershipNo&quot;: {
        &quot;$id&quot;: &quot;#root/payment/membershipNo&quot;,
        &quot;title&quot;: &quot;Membershipno&quot;,
        &quot;type&quot;: &quot;string&quot;,
        &quot;default&quot;: &quot;&quot;,
        &quot;examples&quot;: [
          &quot;10142100469959798&quot;
        ],
        &quot;pattern&quot;: &quot;^.*$&quot;
      },
      &quot;orderTotalAmount&quot;: {
        &quot;$id&quot;: &quot;#root/payment/orderTotalAmount&quot;,
        &quot;title&quot;: &quot;Ordertotalamount&quot;,
        &quot;type&quot;: &quot;string&quot;,
        &quot;default&quot;: &quot;&quot;,
        &quot;examples&quot;: [
          &quot;&quot;
        ],
        &quot;pattern&quot;: &quot;^.*$&quot;
      },
      &quot;priceInfo&quot;: {
        &quot;$id&quot;: &quot;#root/payment/priceInfo&quot;,
        &quot;title&quot;: &quot;Priceinfo&quot;,
        &quot;type&quot;: &quot;object&quot;,
        &quot;required&quot;: [
          &quot;currency&quot;,
          &quot;enterpriseCurrency&quot;
        ],
        &quot;properties&quot;: {
          &quot;currency&quot;: {
            &quot;$id&quot;: &quot;#root/payment/priceInfo/currency&quot;,
            &quot;title&quot;: &quot;Currency&quot;,
            &quot;type&quot;: &quot;string&quot;,
            &quot;default&quot;: &quot;&quot;,
            &quot;examples&quot;: [
              &quot;USD&quot;
            ],
            &quot;pattern&quot;: &quot;^.*$&quot;
          },
          &quot;enterpriseCurrency&quot;: {
            &quot;$id&quot;: &quot;#root/payment/priceInfo/enterpriseCurrency&quot;,
            &quot;title&quot;: &quot;Enterprisecurrency&quot;,
            &quot;type&quot;: &quot;string&quot;,
            &quot;default&quot;: &quot;&quot;,
            &quot;examples&quot;: [
              &quot;USD&quot;
            ],
            &quot;pattern&quot;: &quot;^.*$&quot;
          }
        }
      },
      &quot;paymentMethods&quot;: {
        &quot;$id&quot;: &quot;#root/payment/paymentMethods&quot;,
        &quot;title&quot;: &quot;Paymentmethods&quot;,
        &quot;type&quot;: &quot;array&quot;,
        &quot;default&quot;: [
          
        ],
        &quot;items&quot;: {
          &quot;$id&quot;: &quot;#root/payment/paymentMethods/items&quot;,
          &quot;title&quot;: &quot;Items&quot;,
          &quot;type&quot;: &quot;object&quot;,
          &quot;required&quot;: [
            &quot;sequenceNo&quot;,
            &quot;customerPONo&quot;,
            &quot;displaySvcNo&quot;,
            &quot;maxChargeLimit&quot;,
            &quot;paymentType&quot;,
            &quot;svcNo&quot;,
            &quot;unlimitedCharges&quot;,
            &quot;paymentDetails&quot;
          ],
          &quot;properties&quot;: {
            &quot;sequenceNo&quot;: {
              &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/sequenceNo&quot;,
              &quot;title&quot;: &quot;Sequenceno&quot;,
              &quot;type&quot;: &quot;string&quot;,
              &quot;default&quot;: &quot;&quot;,
              &quot;examples&quot;: [
                &quot;1&quot;
              ],
              &quot;pattern&quot;: &quot;^.*$&quot;
            },
            &quot;customerPONo&quot;: {
              &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/customerPONo&quot;,
              &quot;title&quot;: &quot;Customerpono&quot;,
              &quot;type&quot;: &quot;string&quot;,
              &quot;default&quot;: &quot;&quot;,
              &quot;examples&quot;: [
                &quot;0&quot;
              ],
              &quot;pattern&quot;: &quot;^.*$&quot;
            },
            &quot;displaySvcNo&quot;: {
              &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/displaySvcNo&quot;,
              &quot;title&quot;: &quot;Displaysvcno&quot;,
              &quot;type&quot;: &quot;string&quot;,
              &quot;default&quot;: &quot;&quot;,
              &quot;examples&quot;: [
                &quot;719&quot;
              ],
              &quot;pattern&quot;: &quot;^.*$&quot;
            },
            &quot;maxChargeLimit&quot;: {
              &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/maxChargeLimit&quot;,
              &quot;title&quot;: &quot;Maxchargelimit&quot;,
              &quot;type&quot;: &quot;number&quot;,
              &quot;examples&quot;: [
                159.27
              ],
              &quot;default&quot;: 0.0
            },
            &quot;paymentId1&quot;: {
              &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentReference1&quot;,
              &quot;type&quot;: &quot;string&quot;,
              &quot;default&quot;: &quot;&quot;,
              &quot;examples&quot;: [
                &quot;T4543F/JCgkLnk6OT4qJ/hc+sg==&quot;
              ],
              &quot;pattern&quot;: &quot;^.*$&quot;
            },
            &quot;paymentId2&quot;: {
              &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentReference2&quot;,
              &quot;title&quot;: &quot;Paymentreference2&quot;,
              &quot;type&quot;: &quot;string&quot;,
              &quot;default&quot;: &quot;&quot;,
              &quot;examples&quot;: [
                &quot;ebdbbf2f-aec1-414a-a8b7-ec33de993c02&quot;
              ],
              &quot;pattern&quot;: &quot;^.*$&quot;
            },
            &quot;paymentId3&quot;: {
              &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentReference3&quot;,
              &quot;title&quot;: &quot;Paymentreference3&quot;,
              &quot;type&quot;: &quot;string&quot;,
              &quot;default&quot;: &quot;&quot;,
              &quot;examples&quot;: [
                &quot;Regular&quot;
              ],
              &quot;pattern&quot;: &quot;^.*$&quot;
            },
            &quot;paymentType&quot;: {
              &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentType&quot;,
              &quot;title&quot;: &quot;Paymenttype&quot;,
              &quot;type&quot;: &quot;string&quot;,
              &quot;default&quot;: &quot;&quot;,
              &quot;examples&quot;: [
                &quot;CASH&quot;
              ],
              &quot;pattern&quot;: &quot;^.*$&quot;
            },
            &quot;svcNo&quot;: {
              &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/svcNo&quot;,
              &quot;title&quot;: &quot;Svcno&quot;,
              &quot;type&quot;: &quot;string&quot;,
              &quot;default&quot;: &quot;&quot;,
              &quot;examples&quot;: [
                &quot;6194995892193728&quot;
              ],
              &quot;pattern&quot;: &quot;^.*$&quot;
            },
            &quot;unlimitedCharges&quot;: {
              &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/unlimitedCharges&quot;,
              &quot;title&quot;: &quot;Unlimitedcharges&quot;,
              &quot;type&quot;: &quot;string&quot;,
              &quot;default&quot;: &quot;&quot;,
              &quot;examples&quot;: [
                &quot;N&quot;
              ],
              &quot;pattern&quot;: &quot;^.*$&quot;
            },
            &quot;paymentDetails&quot;: {
              &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentDetails&quot;,
              &quot;title&quot;: &quot;Paymentdetails&quot;,
              &quot;type&quot;: &quot;object&quot;,
              &quot;required&quot;: [
                &quot;internalReturnCode&quot;,
                &quot;authorizationID&quot;,
                &quot;authCode&quot;,
                &quot;internalReturnMessage&quot;,
                &quot;processedAmount&quot;,
                &quot;chargeType&quot;,
                &quot;holdAgainstBook&quot;,
                &quot;authTime&quot;,
                &quot;requestAmount&quot;,
                &quot;authReturnMessage&quot;,
                &quot;authReturnCode&quot;,
                &quot;requestId&quot;
              ],
              &quot;properties&quot;: {
                &quot;internalReturnCode&quot;: {
                  &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentDetails/internalReturnCode&quot;,
                  &quot;title&quot;: &quot;Internalreturncode&quot;,
                  &quot;type&quot;: &quot;string&quot;,
                  &quot;default&quot;: &quot;&quot;,
                  &quot;examples&quot;: [
                    &quot;&quot;
                  ],
                  &quot;pattern&quot;: &quot;^.*$&quot;
                },
                &quot;authorizationID&quot;: {
                  &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentDetails/authorizationID&quot;,
                  &quot;title&quot;: &quot;Authorizationid&quot;,
                  &quot;type&quot;: &quot;string&quot;,
                  &quot;default&quot;: &quot;&quot;,
                  &quot;examples&quot;: [
                    &quot;940799&quot;
                  ],
                  &quot;pattern&quot;: &quot;^.*$&quot;
                },
                &quot;authCode&quot;: {
                  &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentDetails/authCode&quot;,
                  &quot;title&quot;: &quot;Authcode&quot;,
                  &quot;type&quot;: &quot;string&quot;,
                  &quot;default&quot;: &quot;&quot;,
                  &quot;examples&quot;: [
                    &quot;000&quot;
                  ],
                  &quot;pattern&quot;: &quot;^.*$&quot;
                },
                &quot;internalReturnMessage&quot;: {
                  &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentDetails/internalReturnMessage&quot;,
                  &quot;title&quot;: &quot;Internalreturnmessage&quot;,
                  &quot;type&quot;: &quot;string&quot;,
                  &quot;default&quot;: &quot;&quot;,
                  &quot;examples&quot;: [
                    &quot;&quot;
                  ],
                  &quot;pattern&quot;: &quot;^.*$&quot;
                },
                &quot;processedAmount&quot;: {
                  &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentDetails/processedAmount&quot;,
                  &quot;title&quot;: &quot;Processedamount&quot;,
                  &quot;type&quot;: &quot;string&quot;,
                  &quot;default&quot;: &quot;&quot;,
                  &quot;examples&quot;: [
                    &quot;159.27&quot;
                  ],
                  &quot;pattern&quot;: &quot;^.*$&quot;
                },
                &quot;chargeType&quot;: {
                  &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentDetails/chargeType&quot;,
                  &quot;title&quot;: &quot;Chargetype&quot;,
                  &quot;type&quot;: &quot;string&quot;,
                  &quot;default&quot;: &quot;&quot;,
                  &quot;examples&quot;: [
                    &quot;CHARGE&quot;
                  ],
                  &quot;pattern&quot;: &quot;^.*$&quot;
                },
                &quot;holdAgainstBook&quot;: {
                  &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentDetails/holdAgainstBook&quot;,
                  &quot;title&quot;: &quot;Holdagainstbook&quot;,
                  &quot;type&quot;: &quot;string&quot;,
                  &quot;default&quot;: &quot;&quot;,
                  &quot;examples&quot;: [
                    &quot;Y&quot;
                  ],
                  &quot;pattern&quot;: &quot;^.*$&quot;
                },
                &quot;authTime&quot;: {
                  &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentDetails/authTime&quot;,
                  &quot;title&quot;: &quot;Authtime&quot;,
                  &quot;type&quot;: &quot;string&quot;,
                  &quot;default&quot;: &quot;&quot;,
                  &quot;examples&quot;: [
                    &quot;2022-06-08T23:21:49&quot;
                  ],
                  &quot;pattern&quot;: &quot;^.*$&quot;
                },
                &quot;requestAmount&quot;: {
                  &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentDetails/requestAmount&quot;,
                  &quot;title&quot;: &quot;Requestamount&quot;,
                  &quot;type&quot;: &quot;string&quot;,
                  &quot;default&quot;: &quot;&quot;,
                  &quot;examples&quot;: [
                    &quot;159.27&quot;
                  ],
                  &quot;pattern&quot;: &quot;^.*$&quot;
                },
                &quot;authReturnMessage&quot;: {
                  &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentDetails/authReturnMessage&quot;,
                  &quot;title&quot;: &quot;Authreturnmessage&quot;,
                  &quot;type&quot;: &quot;string&quot;,
                  &quot;default&quot;: &quot;&quot;,
                  &quot;examples&quot;: [
                    &quot;&quot;
                  ],
                  &quot;pattern&quot;: &quot;^.*$&quot;
                },
                &quot;authReturnCode&quot;: {
                  &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentDetails/authReturnCode&quot;,
                  &quot;title&quot;: &quot;Authreturncode&quot;,
                  &quot;type&quot;: &quot;string&quot;,
                  &quot;default&quot;: &quot;&quot;,
                  &quot;examples&quot;: [
                    &quot;000&quot;
                  ],
                  &quot;pattern&quot;: &quot;^.*$&quot;
                },
                &quot;requestId&quot;: {
                  &quot;$id&quot;: &quot;#root/payment/paymentMethods/items/paymentDetails/requestId&quot;,
                  &quot;title&quot;: &quot;Requestid&quot;,
                  &quot;type&quot;: &quot;string&quot;,
                  &quot;default&quot;: &quot;&quot;,
                  &quot;examples&quot;: [
                    &quot;6bf404e0-d756-4247-9030-669c83d0d825&quot;
                  ],
                  &quot;pattern&quot;: &quot;^.*$&quot;
                }
              }
            }
          }
        },
        &quot;if&quot;: {
          &quot;properties&quot;: {
            &quot;paymentType&quot;: {
              &quot;enum&quot;: [
                &quot;CASH&quot;
              ]
            }
          }
        },
        &quot;then&quot;: {
          &quot;required&quot;: [
            &quot;paymentId1&quot;
          ]
        }
      },
      &quot;createServiceId&quot;: {
        &quot;$id&quot;: &quot;#root/payment/createServiceId&quot;,
        &quot;title&quot;: &quot;Createserviceid&quot;,
        &quot;type&quot;: &quot;string&quot;,
        &quot;default&quot;: &quot;&quot;,
        &quot;examples&quot;: [
          &quot;PRE_FULFILLMENT&quot;
        ],
        &quot;pattern&quot;: &quot;^.*$&quot;
      }
    }
    }
    }
    }
  </code></pre>