maxItems : Integer
maxItems
IntegerAn array instance is valid if its size is less than, or equal to, the value of this keyword.
Value | This keyword must be set to a zero or positive integer |
---|---|
Kind | Assertion |
Applies To | Array |
Base Dialect | 2020-12 |
Changed In | None |
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 |
Official Tests | draft2020-12/maxItems.json |
Default | None |
Annotation | None |
Affected By | None |
Affects | None |
Also See |
|
The maxItems
keyword restricts array instances to consists of an inclusive
maximum numbers of items.
Best Practice
To restrict array instances to the empty array, prefer using the
const
keyword instead of
setting this keyword to 0
.
Remember that JSON Schema is a constraint-driven language.
Therefore, non-array instances successfully validate against this
keyword. If needed, make use of the type
keyword to constraint
the accepted type accordingly.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"maxItems": 3
}
[ 1, 2, 3, 4 ]
[ 1, true, "hello" ]
[ false, "foo" ]
"Hello World"