allOf : Array<Schema>
allOf
Array<Schema>An instance validates successfully against this keyword if it validates successfully against all schemas defined by this keyword’s value.
Value | This keyword must be set to a non-empty array, where each item is a valid JSON Schema |
---|---|
Kind | Applicator |
Applies To | Any |
Dialect | 2020-12 |
Changed In | None |
Introduced In | Draft 4 |
Vocabulary | Applicator |
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 |
Official Tests | draft2020-12/allOf.json |
Default |
As if it was set to the (invalid) value:
[]
|
Annotation | None |
Affected By | None |
Affects | None |
Also See |
|
The allOf
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.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"allOf": [
{
"properties": {
"foo": { "type": "string" }
},
"required": [ "foo" ]
}
]
}
{ "foo": "foo" }
{ "foo": [ "foo" ] }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"allOf": [
{
"properties": {
"foo": { "type": "string" }
},
"required": [ "foo" ]
},
{
"properties": {
"bar": { "type": "number" }
},
"required": [ "bar" ]
}
]
}
{ "foo": "foo", "bar": 33 }
{ "foo": "foo" }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
true,
{
"properties": {
"foo": { "type": "string" }
},
"required": [ "foo" ]
}
]
}
{ "foo": "foo" }
{ "foo": true }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
false,
{
"properties": {
"foo": { "type": "string" }
},
"required": [ "foo" ]
}
]
}
{ "foo": false }
{ "foo": "foo" }
- Remember, if any subschema within the
allOf
keyword fails validation or has a booleanfalse
value, the entire validation will always fail.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{
"allOf": [
{ "type": "number" }
]
},
{
"allOf": [
{ "minimum": 18 }
]
}
]
}
25
10