maxItems : Integer
maxItems
IntegerAn array instance is valid if its size is less than, or equal to, the value of this keyword.
Kind | Assertion |
---|---|
Applies To | Array |
Dialect | 2020-12 |
Introduced In | Draft 1 |
Vocabulary | Validation |
Specification | https://json-schema.org/draft/2020-12/json-schema-validation.html#section-6.4.1 |
Metaschema | https://json-schema.org/draft/2020-12/meta/validation |
Also see |
|
The maxItems
keyword is used to specify the maximum number of items allowed in an array. It can be used to define constraints on the size of an array within an array instance.
- Applies to arrays only.
- Value must be a non-negative integer.
- An array is valid if it has less than or equal to the specified number of elements.
- Omitting
maxItems
means the array has no upper limit (unbounded).
Note: items
, prefixItems
, and contains
do not affect minItems
. The instance independently evaluated against minItems
(if present).
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"maxItems": 3
}
[ 1, true, "hello" ]
[ 1, 2, "apple", "banana", true ]
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"items": { "type": "boolean" },
"maxItems": 2
}
[ false ]
[ false, false, true ]
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"prefixItems": [
{ "type": "number" },
{ "type": "string" }
],
"contains": { "type": "boolean" },
"maxItems": 3
}
[ 1, "John", false ]
[ 1, "John", "Doe", false ]
[ "John", 1, false ]