dependentSchemas : Object<String, Schema>
dependentSchemas
Object<String, Schema>This keyword specifies subschemas that are evaluated if the instance is an object and contains a certain property.
Value | This keyword must be set to an object where each value is a valid JSON Schema |
---|---|
Kind | Applicator |
Applies To | Object |
Base Dialect | 2020-12 |
Changed In | None |
Introduced In | 2019-09 |
Vocabulary | Applicator |
Specification | https://json-schema.org/draft/2020-12/json-schema-core.html#section-10.2.2.4 |
Metaschema | https://json-schema.org/draft/2020-12/meta/applicator |
Official Tests | draft2020-12/dependentSchemas.json |
Default |
{}
|
Annotation | None |
Affected By | None |
Affects | None |
Also See |
|
The dependentSchemas
keyword restricts object instances to validate against
one or more of the given subschemas if the corresponding properties are
defined. Note that the given subschemas are evaluated against the object that
defines the property dependency.
Digging Deeper
The
dependentRequired
keyword is a specialisation of this
keyword to describe object dependencies that only consist in property
requirement.
Remember that JSON Schema is a constraint-driven language.
Therefore, non-object 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/2020-12/schema",
"dependentSchemas": {
"foo": { "maxProperties": 2 }
}
}
{ "foo": 1, "bar": 2 }
{ "foo": 1, "bar": 2, "baz": 3 }
{ "firstName": "John", "lastName": "Doe", "age": 50 }
{}
"Hello World"
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"dependentSchemas": {
"foo": { "maxProperties": 2 },
"bar": { "minProperties": 2 }
}
}
{ "foo": 1, "bar": 2 }
{ "foo": 1, "bar": 2, "extra": true }
{ "foo": 1 }
{ "foo": 1, "name": "John Doe", "age": 50 }
{ "bar": 2 }
{}
"Hello World"