Schema Nesting
Some keywords take schemas themselves, allowing JSON Schemas to be nested:In-Place Application
These keywords apply subschemas to the same location in the instance as the parent schema is being applied.Subschemas of these keywords evaluate the instance completely independently. The results of one subschema must not impact the results of sibling subschemas. Therefore subschemas may be applied in any order.
Logical Operators
These keywords correspond to logical operators for combining or modifying boolean assertion results:allOf
The value must be a non-empty array of valid JSON Schemas. An instance validates successfully if it validates successfully against all schemas defined by this keyword.anyOf
The value must be a non-empty array of valid JSON Schemas. An instance validates successfully if it validates successfully against at least one schema.When annotations are being collected, all subschemas must be examined so that annotations are collected from each subschema that validates successfully.
oneOf
The value must be a non-empty array of valid JSON Schemas. An instance validates successfully if it validates against exactly one schema.not
The value must be a valid JSON Schema. An instance is valid if it fails to validate successfully against the schema.Conditional Application
These keywords work together to implement conditional application of subschemas.if / then / else
if has no direct effect on the overall validation result. Rather, it controls which of the then or else keywords are evaluated.
There is no default behavior for
if, then, or else when they are not present. They must not be treated as if present with an empty schema.dependentSchemas
This keyword specifies subschemas that are evaluated if the instance is an object and contains a certain property.Applying Subschemas to Arrays
prefixItems
The value must be a non-empty array of valid JSON Schemas. Validation succeeds if each element of the instance validates against the subschema at the same position.items
The value must be a valid JSON Schema. This keyword applies to array elements not covered byprefixItems.
prefixItems does not exist within the same schema object, items applies its subschema to all elements.
contains
The value must be a valid JSON Schema. An instance is valid if the number of elements that are valid against its subschema is within the specified range.minContains is absent. The maximum is unbounded if maxContains is absent.
Applying Subschemas to Objects
properties
The value must be an object where each value is a valid JSON Schema. Validation succeeds if, for each name that appears in both the instance and this keyword’s value, the child instance validates against the corresponding schema.patternProperties
The value must be an object where property names should be valid regular expressions and property values must be valid JSON Schemas.additionalProperties
The value must be a valid JSON Schema. This keyword applies to property values for which neitherproperties nor patternProperties apply.
Omitting this keyword has the same assertion behavior as an empty schema, meaning additional properties are allowed by default.
propertyNames
The value must be a valid JSON Schema. If the instance is an object, this keyword validates if every property name validates against the provided schema.Schema References
$ref
The$ref keyword is used to reference a statically identified schema. Its value must be a string which is an IRI reference.
Other keywords can appear alongside
$ref in the same schema object.$defs
The$defs keyword reserves a location for schema authors to inline re-usable JSON Schemas. The keyword does not directly affect validation.
The value must be an object where each member value is a valid JSON Schema.
dynamicAnchor
These keywords are used when the referencing schema might need to override where a reference in the referenced schema will resolve. This is useful for authoring recursive schemas that can be extended. Resolution of$dynamicRef begins by identifying the outermost schema resource in the dynamic scope which defines a matching $dynamicAnchor.