contains : Schema
contains
SchemaValidation succeeds if the instance contains an element that validates against this schema.
Value |
This keyword must be set to a valid JSON Schema
Hint: Use the jsonschema metaschema and jsonschema lint commands to catch keywords set to invalid values
|
---|---|
Kind | Applicator |
Applies To | Array |
Base Dialect | 2019-09 |
Changed In | None |
Introduced In | Draft 6 |
Vocabulary | Applicator |
Specification | https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.9.3.1.4 |
Metaschema | https://json-schema.org/draft/2019-09/meta/applicator |
Official Tests | draft2019-09/contains.json |
Default |
{}
|
Annotation | None |
Affected By |
|
Affects | None |
Also See |
|
The contains
keyword restricts
array instances to include one or more items (at any location of the array) that
validate against the given subschema. The lower and upper bounds that are
allowed to validate against the given subschema can be controlled using the
minContains
and
maxContains
keywords.
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",
"contains": {
"type": "number",
"multipleOf": 2
}
}
[ "foo", 2, false, [ "bar" ], -5 ]
[ "foo", 2, false, 3, 4, [ "bar" ], -5, -3.0 ]
[ 2, 4, 6, 8, 10, 12 ]
[ "foo", true ]
[]
"Hello World"