I am trying to write Json schema to validate json file with following content:
{
“number” : “1”,
“rootProperty”:
[
{
“property1″:”value1”
},
{
“property2″:”value2”
}
]
}
The schema should handle following scenarios:
- If property2 is present and property1 is missing, error should be reported mentioning that property1 is missing since its mandatory.
- If property1 is present and property2 is missing, error should be reported mentioning that property2 is missing since its mandatory.
- No error should be reported if both property1 and property2 are present.
- No error should be reported if property2 is mentioned first and then property1 is mentioned.
- Error should be reported if any property other than property1 and property2 is mentioned(additionalProperties:false?)
- property1 and property2 should not be repeated(uniqueItems:true?)
Could someone please assist?
Also, whether schema is the right way to handle this depth of validation?
When I tried using “items” keyword for the rootProperty array and mentioned property1 and property2 inside required condition, these conditions are evaluated for every element of the array, which results in error saying property2 is missing in first element and property1 is missing in second element.
Also, using “contains” results in error saying object contains property that couldnt be evaluated against any property or additionalProperties.
Pranav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.