maxContains : Integer
maxContains
IntegerThe number of times that the contains
keyword (if set) successfully validates against the instance must be less 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.4 |
Metaschema | https://json-schema.org/draft/2020-12/meta/validation |
Official Tests | draft2020-12/maxContains.json |
Default | None |
Annotation | None |
Affected By | None |
Affects |
|
Also See |
|
The maxContains
keyword is used in conjunction with the contains
keyword to specify the maximum number of items in an array instance that must validate against the contains
subschema.
- If
contains
is not present within the same schema object, then this keyword has no effect.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"contains": { "type": "string" },
"maxContains": 2
}
[ "Car", "Bus", 1, 2 ]
[ "Car", "Bus", 1, 2, "Bike" ]
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"maxContains": 2
}
// If contains is not present, 'maxContains' has no effect on validation.
[ "John", false, 29, { "foo": "bar" }, [ 5, 7 ] ]
[]