$defs keyword reserves a location for schema authors to inline reusable JSON Schemas into a more general schema. The keyword does not directly affect validation results.
Syntax
object
required
An object where each property value MUST be a valid JSON Schema. Property names are arbitrary identifiers chosen by the schema author.
Purpose
The$defs keyword provides:
- Schema Organization: A standard location for reusable schema components
- Reference Target: Schemas that can be referenced with
$ref - Documentation: Groups related definitions together for readability
- Reserved Location: Ensures this location won’t be redefined by extension keywords
Usage
Basic Example
$defs and referenced by the items keyword.
Multiple Definitions
address schema is reused for both billing and shipping addresses.
Examples
Complex Schema with Nested Definitions
dimensions references positiveNumber).
Recursive Schema
node definition references itself to create a binary tree structure.
Embedded Schema Resources in $defs
$id and can be referenced as person.json. This is useful for bundling multiple schema resources into a single document.
Referencing Definitions
JSON Pointer Syntax
Definitions in$defs are referenced using JSON Pointer syntax:
#refers to the current document root/$defs/navigates to the$defsobject/definitionNameselects the specific definition
External References
Definitions can be referenced from other schema documents:address definition in the external common.json schema.
Validation Behavior
The$defs keyword itself does not affect validation:
"type": "string". The unused definition in $defs has no effect unless referenced.
Naming Conventions
While property names in$defs are arbitrary, common conventions include:
- camelCase:
positiveInteger,emailAddress - PascalCase:
PositiveInteger,EmailAddress - snake_case:
positive_integer,email_address - Descriptive names: Use clear, meaningful names that describe the schema’s purpose
Comparison with Previous Versions
In older JSON Schema drafts,definitions was used instead of $defs:
$ prefix was added to align with other core keywords and emphasize its reserved status.
Bundling Schemas
The$defs keyword is the RECOMMENDED location for bundling external schema resources into a compound document:
$defs (like bundledUser) are for organization and don’t affect references, which use the embedded $id values.