| keyword | allOf | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| signature | Array<Schema> | ||||||||||||||||||||||||||||||
| value | This keyword must be set to a *non-empty* array, where each item is a valid JSON Schema | ||||||||||||||||||||||||||||||
| summary | An instance validates successfully against this keyword if it validates successfully against all schemas defined by this keyword's value. | ||||||||||||||||||||||||||||||
| kind |
|
||||||||||||||||||||||||||||||
| instance |
|
||||||||||||||||||||||||||||||
| specification | https://json-schema.org/draft/2020-12/json-schema-core.html#section-10.2.1.1 | ||||||||||||||||||||||||||||||
| metaschema | https://json-schema.org/draft/2020-12/meta/applicator | ||||||||||||||||||||||||||||||
| default |
|
||||||||||||||||||||||||||||||
| tests |
|
||||||||||||||||||||||||||||||
| index | -99999 | ||||||||||||||||||||||||||||||
| introduced_in | draft4 | ||||||||||||||||||||||||||||||
| related |
|
The {{}} keyword is used to specify that a given instance must validate against all of the subschemas provided within an array. It's essentially a logical "AND" operation where all conditions must be met for validation to pass.
{{<schema Schema with 'allOf' keyword containing only one subschema>}}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"allOf": [
{
"properties": {
"foo": { "type": "string" }
},
"required": [ "foo" ]
}
]
}
{{}}
{{<instance-pass An instance conforming to all the subschemas of 'allOf' is valid>}}
{ "foo": "foo" }
{{}}
{{<instance-fail The value of 'foo' must be a string>}}
{ "foo": [ "foo" ] }
{{}}
{{<schema Schema with 'allOf' keyword containing multiple subschemas>}}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"allOf": [
{
"properties": {
"foo": { "type": "string" }
},
"required": [ "foo" ]
},
{
"properties": {
"bar": { "type": "number" }
},
"required": [ "bar" ]
}
]
}
{{}}
{{<instance-pass An instance conforming to all the subschemas of 'allOf' is valid>}}
{ "foo": "foo", "bar": 33 }
{{}}
{{<instance-fail An instance that does not conform to both subschemas within 'allOf' is invalid>}}
{ "foo": "foo" }
{{}}
{{<schema Schema with 'allOf' keyword containing some boolean subschemas>}}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
true,
{
"properties": {
"foo": { "type": "string" }
},
"required": [ "foo" ]
}
]
}
{{}}
{{<instance-pass An instance conforming to all the subschemas of 'allOf' is valid>}}
{ "foo": "foo" }
{{}}
{{<instance-fail The value of 'foo' must be a string>}}
{ "foo": true }
{{}}
{{<schema Schema with 'allOf' keyword containing some boolean subschemas>}}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
false,
{
"properties": {
"foo": { "type": "string" }
},
"required": [ "foo" ]
}
]
}
{{}}
{{<instance-fail An instance not conforming to the second subschema of 'allOf' is invalid>}}
{ "foo": false }
{{}}
{{<instance-fail An instance conforming to the second subschema of 'allOf' is also invalid>}}
{ "foo": "foo" }
{{}}
- Remember, if any subschema within the {{}} keyword fails validation or has a boolean
falsevalue, the entire validation will always fail.
{{<schema Schema with nested 'allOf'>}}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{
"allOf": [
{ "type": "number" }
]
},
{
"allOf": [
{ "minimum": 18 }
]
}
]
}
{{}}
{{<instance-pass An instance conforming to all the subschemas including the nested 'allOf' is valid>}}
25
{{}}
{{<instance-fail The validation fails due to the 2nd subschema of the top-level 'allOf'>}}
10
{{}}