Skip to main content
Composition keywords let you define shared sub-schemas and combine validation rules.

Supported keywords

Reuse with $defs and $ref

Define shared sub-schemas once, then reference them.
$ref support is for local references (for example #/$defs/...).

allOf

Combine constraints that must all apply.
Pydantic example is omitted because there is no direct allOf keyword mapping.

anyOf / oneOf

Both anyOf and oneOf behave the same way: exactly one subschema must match. Use a discriminator field plus const to make branches explicit.

not

Reject values that match a subschema:
JSON Schema
Pydantic and Zod examples are omitted here because there is no direct keyword mapping for JSON Schema not.
This accepts any non-empty string.

Recursive schemas

Recursive local references are supported: