$defs : Object<String, Schema>

$defs

Object<String, Schema>

This keyword reserves a location for schema authors to inline re-usable JSON Schemas into a more general schema.

Value This keyword must be set to an object where each value is a valid JSON Schema Hint: Use the jsonschema metaschema and jsonschema lint commands to catch keywords set to invalid values
Kind Reserved Location
Applies To Any
Base Dialect 2020-12
Changed In None
Introduced In 2019-09
Vocabulary Core
Specification https://json-schema.org/draft/2020-12/json-schema-core.html#section-8.2.4
Metaschema https://json-schema.org/draft/2020-12/meta/core
Official Tests draft2020-12/defs.json
Default {}
Annotation None
Affected By None
Affects None
Also See

The $defs keyword is a container for storing re-usable schemas within a schema resource, which can be referenced using the $ref or $dynamicRef keywords. From a software engineering point of view, this keyword is analogous to defining internal helper functions as part of a larger program.

Examples

A schema that declares a helper schema to reduce duplication when defining multiple properties Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "firstName": { "$ref": "#/$defs/nonEmptyString" },
    "lastName": { "$ref": "#/$defs/nonEmptyString" }
  },
  "$defs": {
    "nonEmptyString": {
      "type": "string",
      "minLength": 1
    }
  }
}
Valid An object value with non-empty first and last names is valid Instance
{ "firstName": "John", "lastName": "Doe" }
Invalid An object value with empty first and last names is invalid Instance
{ "firstName": "", "lastName": "" }