Tools, FAQ, Tutorials:
JSON Schema Validation for JSON Array Values
What validation keywords I can use in JSON Schema to specifically validate JSON Array values?
✍: FYIcenter.com
The current JSON Schema specification supports the following validation keywords
to specifically validate JSON Array values.
They are not applied if the JSON instance is not a JSON Array.
"items" - If the JSON instance is an array, its elements must be valid against given schemas.
If a single schema is given in "items", all elements in the JSON instance array must be valid against the given schema. For example:
JSON Schema: {"items": {"type": "string"} } Valid JSON instance: ["1", "2", "3"] Valid JSON instance: 3.14159 Invalid JSON instance: [1,2,3]
If an array of schemas is given in "items", for each given schema, the element in the JSON instance array at the same index position must be valid against the schema. Additional elements in the JSON instance array are valid by default. For example:
JSON Schema: {"items": [ {"type": "string"}, {"type": "number"} ] } Valid JSON instance: ["age",25,true] Valid JSON instance: {"age":25} Invalid JSON instance: ["age","25",true]
"additionalItems" - If the JSON instance is an array, and it have more elements than what "items" provides, additional elements are validated against the given schema. For example:
JSON Schema: {"items": [ {"type": "string"}, {"type": "number"} ], "additionalItems": {"type": "boolean"} } Valid JSON instance: ["age",25,true] Valid JSON instance: 3.14159 Invalid JSON instance: ["age",25,"true"]
"additionalItems" is behave like "items", if "items" is not specified. For example:
JSON Schema: {"additionalItems": {"type": "number"} } Valid JSON instance: [1, 2, 3] Invalid JSON instance: ["age",25,true]
"additionalItems" is ignored, if "items" is specified with a single schema. For example:
JSON Schema: {"items": {"type": "string"}, "additionalItems": {"type": "number"} } Valid JSON instance: ["One","Two","Three"] Invalid JSON instance: [1, 2, 3]
"maxItems" - If the JSON instance is an array, the number of its elements must be less than or equal to the given value. For example:
JSON Schema: {"maxItems": 3} Valid JSON instance: ["One","Two","Three"] Valid JSON instance: 123 Invalid JSON instance: ["One","Two","Three", "Four"]
"minItems" - If the JSON instance is an array, the number of its elements must be greater than or equal to the given value. For example:
JSON Schema: {"minItems": 3} Valid JSON instance: ["One","Two","Three"] Valid JSON instance: 123 Invalid JSON instance: ["One","Two"]
"uniqueItems" - If the JSON instance is an array, the uniqueness of its elements must match the given boolean value For example:
JSON Schema: {"uniqueItems": true} Valid JSON instance: ["One","Two","Three"] Valid JSON instance: 123 Invalid JSON instance: [9,1,1]
"contains" - If the JSON instance is an array, it must contains at least one element that is valid against the given schema. For example:
JSON Schema: {"contains": {"type": "number"} } Valid JSON instance: ["One",2,"Three"] Valid JSON instance: "Hi" Invalid JSON instance: ["One","Two","Three"]
⇒ JSON Schema Validation for JSON Object Values
2017-09-01, 3372🔥, 0💬
Popular Posts:
How to add images to my EPUB books Images can be added into book content using the XHTML "img" eleme...
How to add request query string Parameters to my Azure API operation 2017 version to make it more us...
How to add request query string Parameters to my Azure API operation to make it more user friendly? ...
How to use the "set-body" Policy Statement for an Azure API service operation? The "set-body" Policy...
How to create a new API on the Publisher Dashboard of an Azure API Management Service? If you are ne...