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
Base 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 restricts instances to validate against every given subschema. This keyword can be thought of as a logical conjunction (AND) operation, as instances are valid if they satisfy every constraint of every subschema (the intersection of the constraints).

This keyword is equivalent to the && operator found in most programming languages. For example:

bool valid = A && B && C;

As a reference, the following boolean truth table considers the evaluation result of this keyword given 3 subschemas: A, B, and C.

allOf Subschema A Subschema B Subschema C
Invalid Invalid Invalid Invalid
Invalid Invalid Invalid Valid
Invalid Invalid Valid Invalid
Invalid Invalid Valid Valid
Invalid Valid Invalid Invalid
Invalid Valid Invalid Valid
Invalid Valid Valid Invalid
Valid Valid Valid Valid

Examples

A schema that constrains instances with two internally referenced schemas Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "allOf": [
    { "$ref": "#/$defs/foo" },
    { "$ref": "#/$defs/bar" }
  ],
  "$defs": {
    "foo": { "type": "number" },
    "bar": { "type": "integer" }
  }
}
Valid A value that matches both subschemas is valid Instance
12345
Invalid A value that only matches one of the subschemas is invalid Instance
3.14
Invalid A value that does not match any of the subschemas is invalid Instance
"Hello World"