minContains : Integer
minContains
IntegerThe 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
Hint: Use the jsonschema metaschema and jsonschema lint commands to catch keywords set to invalid values
|
|---|---|
| Kind | Assertion |
| Applies To | Array |
| Base Dialect | 2019-09 |
| Changed In | None |
| Introduced In | 2019-09 |
| Vocabulary | Validation |
| Specification | https://json-schema.org/draft/2019-09/draft-handrews-json-schema-validation-02#rfc.section.6.4.5 |
| Metaschema | https://json-schema.org/draft/2019-09/meta/validation |
| Official Tests | draft2019-09/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.
Common Pitfall
Keep in mind that when collecting annotations, the evaluator might need to exhaustively check every item in the array past the containment lower bound instead of short-circuiting validation, potentially introducing additional computational overhead.
For example, consider an array of 10 items where 5 of its items validate
against the contains subschema
and minContains is set to to
2. When not collecting annotations, validation will stop after encountering the
second match. However, when collecting annotations, validation will have to
proceed past the second match to report the 5 matching
indexes.
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
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"minContains": 2,
"contains": {
"type": "number",
"multipleOf": 2
}
}[ "foo", 2, false, 3, 4, [ "bar" ], -5 ]{ "keyword": "/contains", "instance": "", "value": [ 1, 4 ] }[ "foo", 2, false, 3, 4, [ "bar" ], -5, -3.0 ]{ "keyword": "/contains", "instance": "", "value": [ 1, 4, 7 ] }[ "foo", 2, false, [ "bar" ], -5 ][ "foo", true ][]"Hello World"{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"minContains": 2
}[ "John", false, 29, { "foo": "bar" }, [ 5, 7 ] ][]"Hello World"