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, ∼5180🔥, 0💬
Popular Posts:
Where to find tutorials on OpenID? Here is a large collection of tutorials to answer many frequently...
What properties and functions are supported on http.client.HTTPResponse objects? If you get an http....
What Happens If One Row Has Missing Columns? What happens if one row has missing columns? Most brows...
How to use urllib.parse.urlencode() function to encode HTTP POST data? My form data has special char...
How to use the built-in "context" object in Policy expressions? The built-in "context" object can be...