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.

Kind Applicator
Applies To Any
Dialect 2020-12
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
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.

  • The value of this keyword must be a non-empty array.
  • Each item of the array must be a valid JSON Schema.

Examples

Schema with 'allOf' keyword containing only one subschema Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "allOf": [
    {
      "properties": {
        "foo": { "type": "string" }
      },
      "required": [ "foo" ]
    }
  ]
}
An instance conforming to all the subschemas of 'allOf' is valid Instance
{ "foo": "foo" }
The value of 'foo' must be a string Instance
{ "foo": [ "foo" ] }
Schema with 'allOf' keyword containing multiple subschemas Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "allOf": [
    {
      "properties": {
        "foo": { "type": "string" }
      },
      "required": [ "foo" ]
    },
    {
      "properties": {
        "bar": { "type": "number" }
      },
      "required": [ "bar" ]
    }
  ]
}
An instance conforming to all the subschemas of 'allOf' is valid Instance
{ "foo": "foo", "bar": 33 }
An instance that does not conform to both subschemas within 'allOf' is invalid Instance
{ "foo": "foo" }
Schema with 'allOf' keyword containing some boolean subschemas Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "allOf": [
    true,
    {
      "properties": {
        "foo": { "type": "string" }
      },
      "required": [ "foo" ]
    }
  ]
}
An instance conforming to all the subschemas of 'allOf' is valid Instance
{ "foo": "foo" }
The value of 'foo' must be a string Instance
{ "foo": true }
Schema with 'allOf' keyword containing some boolean subschemas Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "allOf": [
    false,
    {
      "properties": {
        "foo": { "type": "string" }
      },
      "required": [ "foo" ]
    }
  ]
}
An instance not conforming to the second subschema of 'allOf' is invalid Instance
{ "foo": false }
An instance conforming to the second subschema of 'allOf' is also invalid Instance
{ "foo": "foo" }
  • Remember, if any subschema within the allOf keyword fails validation or has a boolean false value, the entire validation will always fail.
Schema with nested 'allOf' Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "allOf": [
    {
      "allOf": [
        { "type": "number" }
      ]
    },
    {
      "allOf": [
        { "minimum": 18 }
      ]
    }
  ]
}
An instance conforming to all the subschemas including the nested 'allOf' is valid Instance
25
The validation fails due to the 2nd subschema of the top-level 'allOf' Instance
10