Skip to content

How to validate mandatory key values under array of Object and also allow new optional values ? #649

Closed Answered by jdesrosiers
chaitanyak4888 asked this question in Q&A
Discussion options

You must be logged in to vote

You're looking for the contains keyword. The following checks if the array contains an object with property "accountType" and value "Loan". You can use the same pattern to express that "Savings" is required and use allOf to combine the two assertions.

{
  "contains": {
    "type": "object",
    "properties": {
      "accountType": { "const": "Loan" }
    },
    "required": ["accountType"]
  }
}

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@chaitanyak4888
Comment options

Answer selected by chaitanyak4888
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants