minItems : Integer
minItems
IntegerAn array instance is valid if its size is greater 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 |
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.2 |
Metaschema | https://json-schema.org/draft/2020-12/meta/validation |
Official Tests | draft2020-12/minItems.json |
Default |
0
|
Annotation | None |
Affected By | None |
Affects | None |
Also See |
|
The minItems
keyword specifies the minimum number of items that must be present in an array. It can be used to define constraints on the size of an array, ensuring that it contains at least a certain number of elements.
- An array is valid if it has at least the specified number of elements.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"minItems": 3
}
[ 1, true, "hello" ]
[ 1, "apple" ]
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"items": { "type": "boolean" },
"minItems": 2
}
[ false, false, true ]
[ false ]
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"prefixItems": [
{ "type": "number" },
{ "type": "string" }
],
"contains": { "type": "boolean" },
"minItems": 3
}
[ 1, "John", false ]
[ 1, "John" ]
[ "John", 1, false ]