Here is the desired schema and json for illustration purpose. Please see the link below.
{
"id": "123" ,
"ts": "1234567890",
"complex_rules":
[
{
"type":"admin",
"rule":{
"rights":"all",
"remarks": "some admin remarks"
}
},
{
"type":"guest",
"rights": "limited"
},
{
"type":"anonymous",
"rights": "blocked"
}
]
}
The 'complex_rules' is an array of json object:
- With type either be a : "admin", "guest", "anonymous" and the 'type' attribute is MANDATORY.
- Each object in array can have its own structure, but the type can be either of: "admin", "guest", "anonymous" only. No other type attribute is acceptable.
The conditions to evaluate:
- The type of object in the array cannot re-occur in the array. (I know this seems to be not possible, so we can ignore this)
- If attribute "rights" in the {type=admin object} with any value, then we cannot have "rights": "limited" or any value in {type=guest object}. The JSON Schema validation must complain about this.
- Another twist, either object {type":"guest"}or {type":"anonymous"} can exist. Both types cannot coexist along with other types.
----Update The above link is the solution this question.
rightsunderrule, so you'd have to make the same change in the schema.