maxItems : Integer

maxItems

Integer

An 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.

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

A schema that constrains array instances to contain at most 3 items Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "maxItems": 3
}
Invalid An array value with more than 3 items is invalid Instance
[ 1, 2, 3, 4 ]
Valid An array value with 3 items is valid Instance
[ 1, true, "hello" ]
Valid An array value with less than 3 items is valid Instance
[ false, "foo" ]
Valid A non-array value is valid Instance
"Hello World"