minContains : Integer

minContains

Integer

The number of times that the contains keyword (if set) successfully validates against the instance must be greater than or equal to the given integer.

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 2019-09
Vocabulary Validation
Specification https://json-schema.org/draft/2020-12/json-schema-validation.html#section-6.4.5
Metaschema https://json-schema.org/draft/2020-12/meta/validation
Official Tests draft2020-12/minContains.json
Default 0
Annotation None
Affected By None
Affects
Also See

The minContains keyword is used in conjunction with the contains keyword to specify the minimum number of items in an array instance that must validate against the contains subschema.

  • This keyword applies only to arrays.
  • The value of this keyword must be a non-negative integer.
  • If contains is not present within the same schema object, then this keyword has no effect.

Examples

Schema with the 'minContains' and 'contains' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "contains": { "type": "string" },
  "minContains": 2
}
Valid An array instance with 2 or more items successfully validating against the 'contains' subschema is valid Instance
[ "Car", "Bus", 1, 2, "Bike" ]
Invalid An array instance with less than 2 items successfully validating against the 'contains' subschema is invalid Instance
[ "Car", 1 ]
Invalid An empty array is invalid Instance
[]
Schema with the 'minContains' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "minContains": 2
}
// If contains is not present, 'minContains' has no effect on validation.
Valid An array instance with any items is valid Instance
[ "John", false, 29, { "foo": "bar" }, [ 5, 7 ] ]
Valid An empty array is also valid Instance
[]
Schema with the 'minContains' and 'contains' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "contains": { "type": "string" },
  "minContains": 0
}
Valid An array instance with any items is valid Instance
[ "John", false, 29, { "foo": "bar" }, [ 5, 7 ] ]
Valid An empty array is also valid Instance
[]
  • It is important to note that the contains keyword requires at least one item of the array instance to validate against its subschema. However, when minContains is set to 0, the schema would behave as if it does not have the contains keyword, as shown in the above example.