$vocabulary : Object<URI, Boolean>
$vocabulary
Object<URI, Boolean>This keyword is used in meta-schemas to identify the required and optional vocabularies available for use in schemas described by that meta-schema.
Value | This keyword must be set to an object where each key is a JSON Schema vocabulary URI and each value is a boolean that represents whether the corresponding vocabulary is considered optional (false) or required (true) |
---|---|
Kind | Identifier |
Applies To | Any |
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.1.2 |
Metaschema | https://json-schema.org/draft/2020-12/meta/core |
Official Tests | draft2020-12/vocabulary.json |
Default | Implementation dependent |
Annotation | None |
Affected By | None |
Affects | None |
Also See |
The $vocabulary
keyword is used in meta-schemas to identify the vocabularies available for use in schemas described by that meta-schema. It is also used to indicate whether each vocabulary is required or optional, in the sense that an implementation must understand the required vocabularies in order to successfully process the schema.
-
Required and optional vocabularies: If a vocabulary is required and an implementation does not recognize it, it must refuse to process any schemas that declare this meta-schema. If a vocabulary is optional, implementations that do not recognize it should proceed with processing such schemas.
-
Mandatory: The Core vocabulary MUST always be included and set as required.
-
Non-inheritability: Vocabularies defined in one meta-schema do not automatically apply to another meta-schema that references it. Each meta-schema must declare its vocabularies independently.
-
Recommendation: Meta-schemas should always declare this keyword to clearly specify the vocabularies in use and avoid ambiguities.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://json-schema.org/draft/2020-12/schema",
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/core": true,
"https://json-schema.org/draft/2020-12/vocab/applicator": true,
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
"https://json-schema.org/draft/2020-12/vocab/validation": true,
"https://json-schema.org/draft/2020-12/vocab/meta-data": true,
"https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
"https://json-schema.org/draft/2020-12/vocab/content": true
},
"allOf" : [
{ "$ref": "meta/core" },
{ "$ref": "meta/applicator" },
{ "$ref": "meta/unevaluated" },
{ "$ref": "meta/validation" },
{ "$ref": "meta/meta-data" },
{ "$ref": "meta/format-annotation" },
{ "$ref": "meta/content" }
],
// ...
}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/meta/example-vocab",
"$dynamicAnchor": "meta",
"type": [ "object", "boolean" ],
"properties": {
"minDate": {
"type": "string",
"pattern": "\\d\\d\\d\\d-\\d\\d-\\d\\d",
"format": "date"
}
}
}
Digging Deeper
The
$dynamicAnchor: meta
declaration is set by convention to meta
on the official meta-schemas. This setting serves as a mechanism to enable meta-schema extensibility. By declaring $dynamicAnchor: meta
here, JSON Schema is configured to validate every subschema of the instance schema against the meta-schema, extending validation beyond just the top level.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/schema-required",
"$dynamicAnchor": "meta",
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/core": true,
"https://example.com/vocab/example-vocab": "true"
},
"allOf": [
{ "$ref": "https://json-schema.org/draft/2020-12/meta/core" },
{ "$ref": "https://example.com/meta/example-vocab" }
]
}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/schema-optional",
"$dynamicAnchor": "meta",
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/core": true,
"https://example.com/vocab/example-vocab": "false"
},
"allOf": [
{ "$ref": "https://json-schema.org/draft/2020-12/meta/core" },
{ "$ref": "https://example.com/meta/example-vocab" }
]
}
{
"$schema": "https://example.com/schema-required",
"$id": "https://my-schema.com",
"minDate": "2024-05-17"
}