dependencies - sgpinkus/json-schema GitHub Wiki
THIS WIKI IS OBSOLETE. PLEASE SEE THE NEW JSON-SCHEMA-ORG/JSON-SCHEMA-SPEC REPOSITORY.
NOTE: This proposal with this or very similar language was included in Draft 04
An object instance is valid against this keyword if it satisfies both property dependencies (if any) and schema dependencies (if any), see below.
The value of this keyword MUST be an object. A member's value for this object MUST be either a string, an array or an object.
If the value is an array, then elements of this array MUST be string values.
If the value is an object, then this object MUST be a valid JSON Schema.
If a member's value of the dependencies keyword is either a string or an array of strings, then this is a property dependency. Example:
{
"dependencies": {
"a": "b",
"c": [ "d", "e" ]
}
}
In the example schema above:
- if the instance to validate has a member named "a", then it MUST also have a member named "b" in order to be valid;
- if it has a member named "c", then it MUST also have members named "d" and "e" in order to be valid.
This instance, for example, is valid:
{
"a": true,
"b": null
}
but this one is not:
{
"c": false,
"d": 31
}
since the required property "e" is missing.
If a member's value of the dependencies keyword is an object, therefore a JSON Schema, this is a schema dependency. Example:
{
"dependencies": {
"a": {
"properties": {
"x": { "type": "integer" }
}
}
}
}
In the example schema above, if the instance to validate has a member named "a", then the instance MUST also be valid against the associated schema (the member's value).
Note that it is the INSTANCE ITSELF which must be valid against the schema, NOT the instance member's value (ie, not the value of "a" in this example).
With the schema above, the following instance is valid:
{
"a": "whatever",
"x": 131
}
while the following is not:
{
"a": true,
"x": 1.1
}
since "x" is not an integer.