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 |
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 allows you to define dependencies between properties based on the presence of other properties within an instance. It extends the functionality of the dependentRequired
keyword by allowing you to pass in a full schema. The instance will be considered valid only if the dependent properties adhere to the dependentSchemas
schema.
- Each key in the object represents a property name.
- Instance is valid if the associated property is present and conforms to the subschema.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" },
"license": { "type": "string" }
},
"dependentSchemas": {
"license": {
"properties": {
"age": { "type": "number" }
},
"required": [ "age" ]
}
}
}
{
"name": "John",
"age": 25,
"license": "XYZ123"
}
{
"name": "John",
"age": "25",
"license": "XYZ123"
}
{
"name": "John",
"age": "25"
}
{
"name": "John",
"license": "XYZ123"
}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" }
},
"dependentSchemas": {
"name": {
"properties": {
"age": { "type": "number" }
},
"dependentSchemas": {
"age": {
"properties": {
"eligible": { "type": "boolean" }
},
"required": [ "eligible" ]
}
},
"required": [ "age" ]
}
}
}
{
"name": "John",
"age": 15,
"eligible": false
}
{
"name": "manager",
"age": "25",
"eligible": true
}
{
"age": "25",
"eligible": true
}
{
"age": "25",
"eligible": true
}
{
"name": "manager",
"age": "25"
}