Conditional statement is not working in json schema validation
Here is a schema which works for your given JSON instance with the following validation rules:
Type can be static
or scrollable
If type is static
, max one item in tiles
array, and object properties must be context
, collection
, and tile_type
.
If type is scrollable
, at least two items in tiles
array, and object properties must be name
, location
, and tile_type
.
Items in a scrollable
tile must be unique.
In addition to this the tile elemnts also different
Sorry, this is not possible with JSON Schema.
Also tested using the same online validator you used.
{ "type": "array", "items": { "properties": { "views": { "type": "array", "items": { "properties": { "groups": { "type": "array", "items": { "oneOf": [ { "properties": { "type": { "const": "static" }, "tiles": { "type": "array", "maxItems": 1, "items": { "propertyNames": { "enum": [ "context", "collection", "tile_type" ] }, "required": [ "context", "collection", "tile_type" ] } } } }, { "properties": { "type": { "const": "scrollable" }, "tiles": { "type": "array", "minItems": 2, "items": { "propertyNames": { "enum": [ "name", "location", "tile_type" ] }, "required": [ "name", "location", "tile_type" ] } } } } ] } } } } } } }}