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
Base 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 modifies the contains keyword to constrain array instances to the given minimum number of containment matches. This keyword has no effect if the contains keyword is not declared.

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 least two even numbers Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "minContains": 2,
  "contains": {
    "type": "number",
    "multipleOf": 2
  }
}
Valid An array value with two even numbers is valid Instance
[ "foo", 2, false, 3, 4, [ "bar" ], -5 ]
Annotations
{ "keyword": "/contains", "instance": "", "value": [ 1, 4 ] }
Valid An array value with more than two even numbers is valid Instance
[ "foo", 2, false, 3, 4, [ "bar" ], -5, -3.0 ]
Annotations
{ "keyword": "/contains", "instance": "", "value": [ 1, 4, 7 ] }
Invalid An array value with one even number is invalid Instance
[ "foo", 2, false, [ "bar" ], -5 ]
Invalid An array value without any even number is invalid Instance
[ "foo", true ]
Invalid An empty array value is invalid Instance
[]
Valid A non-array value is valid Instance
"Hello World"
A schema that incorrectly constrains minimum containment without constrainining containment Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "minContains": 2
}
Valid An array value with arbitrary items is valid Instance
[ "John", false, 29, { "foo": "bar" }, [ 5, 7 ] ]
Valid An empty array is valid Instance
[]
Valid A non-array value is valid Instance
"Hello World"