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 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" ]
    }
  ]
}
Valid An instance conforming to all the subschemas of 'allOf' is valid Instance
{ "foo": "foo" }
Invalid 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" ]
    }
  ]
}
Valid An instance conforming to all the subschemas of 'allOf' is valid Instance
{ "foo": "foo", "bar": 33 }
Invalid 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" ]
    }
  ]
}
Valid An instance conforming to all the subschemas of 'allOf' is valid Instance
{ "foo": "foo" }
Invalid 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" ]
    }
  ]
}
Invalid An instance not conforming to the second subschema of 'allOf' is invalid Instance
{ "foo": false }
Invalid 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 }
      ]
    }
  ]
}
Valid An instance conforming to all the subschemas including the nested 'allOf' is valid Instance
25
Invalid The validation fails due to the 2nd subschema of the top-level 'allOf' Instance
10