contains : Schema

contains

Schema

Validation 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

A schema that constrains array instances to contain at least one even number Schema
{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "contains": {
    "type": "number",
    "multipleOf": 2
  }
}
Valid An array value with one even number is valid Instance
[ "foo", 2, false, [ "bar" ], -5 ]
Valid An array value with multiple even numbers is valid Instance
[ "foo", 2, false, 3, 4, [ "bar" ], -5, -3.0 ]
Valid An array value that solely consists of even numbers is valid Instance
[ 2, 4, 6, 8, 10, 12 ]
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"