I want to make a schema of json file.It's for an array of products. The json schema is similar as below:
< "$schema": "http://json-schema.org/draft-04/schema#", "title": "Product set", "type": "array", "items": < "title": "Product", "type": "object", "properties": < "id": < "description": "The unique identifier for a product", "type": "number" >, "name": < "type": "string" >, "price": < "type": "number", "minimum": 0, "exclusiveMinimum": true >, "tags": < "type": "array", "items": < "type": "string" >, "minItems": 1, "uniqueItems": true >, "dimensions": < "type": "object", "properties": < "length": , "width": , "height": >, "required": ["length", "width", "height"] >, "warehouseLocation": < "description": "Coordinates of the warehouse with the product", "$ref": "http://json-schema.org/geo" >>, "required": ["id", "name", "price"] > >
The array should at least one item in it. How can I define the minimum of the array? Do I need to add the minimun defination?
109 1 1 silver badge 10 10 bronze badges asked May 16, 2013 at 9:18 1,237 1 1 gold badge 11 11 silver badges 18 18 bronze badgesTo set the minimum # of item in an array, use the "minItems" .
< "$schema": "http://json-schema.org/draft-04/schema#", "title": "Product", "description": "A product from Acme's catalog", "type": "object", "properties": < . "tags": < "type": "array", "items": < "type": "string" >, "minItems": 1, "maxItems": 4, "uniqueItems": true > >, "required": ["id", "name", "price"] >