minItems : Integer

minItems

Integer

An array instance is valid if its size is greater 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.2
Metaschema https://json-schema.org/draft/2020-12/meta/validation
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.

  • Applies to arrays only.
  • Value must be a non-negative integer.
  • An array is valid if it has at least the specified number of elements.
  • Omitting minItems keyword has the same behavior as a value of 0.

Examples

Schema with 'minItems' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "minItems": 3
}
An array instance with 3 or more elements is valid Instance
[ 1, true, "hello" ]
An array instance with less than 3 elements is invalid Instance
[ 1, "apple" ]
Schema with the 'minItems' and 'items' keywords Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "items": { "type": "boolean" },
  "minItems": 2
}
An array instance containing 2 or more items, which conform to the 'items' subschema, is valid Instance
[ false, false, true ]
An array instance with less than 2 elements is invalid Instance
[ false ]
Schema with the 'minItems', 'prefixItems' and 'contains' keywords Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "prefixItems": [
    { "type": "number" },
    { "type": "string" }
  ],
  "contains": { "type": "boolean" },
  "minItems": 3
}
An array instance containing 3 or more items, which successfully validates against 'prefixItems' and 'contains', is valid Instance
[ 1, "John", false ]
An array instance with less than 3 elements is invalid Instance
[ 1, "John" ]
First and second items should be number and string respectively Instance
[ "John", 1, false ]