How to validate mandatory key values under array of Object and also allow new optional values ? #649
-
{
"test": {
"bundle": [
{
"account": {
"accountType": "Savings",
"somekeyc": "testc"
}
},
{
"account": {
"accountType": "Current",
"somekeya": "testa"
}
},
{
"account": {
"accountType": "Loan",
"somekeyb": "testb"
}
}
]
}
} I need accountType as required field and the values of it should be "Loan" and "Savings" both these two arrays should be present for a given Json to validate if not throw it as invalid Loan and Savings are missing from the Array. And accountType should allow new values other than the two mentioned. Please help me out. I tried with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You're looking for the {
"contains": {
"type": "object",
"properties": {
"accountType": { "const": "Loan" }
},
"required": ["accountType"]
}
} |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
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 useallOf
to combine the two assertions.