What are Vocabularies?
Vocabularies are the mechanism by which JSON Schema is extended and customized. A vocabulary is a set of related keywords that work together to provide specific functionality. Each vocabulary is identified by a URI and can be required or optional in a schema.Vocabularies enable JSON Schema to be flexible and extensible while maintaining clear boundaries between different sets of functionality.
The $vocabulary Keyword
The $vocabulary keyword is used in meta-schemas to declare which vocabularies are available. Its value MUST be an object where:
- Each key is a vocabulary URI
- Each value is a boolean:
true- The vocabulary is required (implementations MUST support it)false- The vocabulary is optional (implementations MAY support it)
Core Vocabularies
JSON Schema defines several standard vocabularies:Core Vocabulary
URI:https://json-schema.org/draft/next/vocab/core
Purpose: Essential keywords that MUST be supported by all implementations.
The core vocabulary includes keywords that begin with $ and are fundamental to processing schemas:
$schema- Declares the meta-schema and dialect$id- Identifies the schema resource$ref- References another schema$dynamicRef/$dynamicAnchor- Dynamic references for advanced use cases$defs- Defines reusable schema components$comment- Provides comments for schema authors$vocabulary- Declares available vocabularies (in meta-schemas)
The
$ prefix is reserved for core keywords. Extension keywords MUST NOT begin with $.Applicator Vocabulary
URI:https://json-schema.org/draft/next/vocab/applicator
Purpose: Keywords that apply subschemas to instances.
Applicator keywords determine which schemas are applied to which parts of an instance:
Logic applicators:
allOf- Instance must be valid against all subschemasanyOf- Instance must be valid against at least one subschemaoneOf- Instance must be valid against exactly one subschemanot- Instance must NOT be valid against the subschema
if/then/else- Conditional application based on validation resultdependentSchemas- Apply schemas based on presence of properties
prefixItems- Apply schemas to array elements by positionitems- Apply schema to remaining array elementscontains- At least one array element must matchminContains/maxContains- Constrain number of matching elements
properties- Apply schemas to named object propertiespatternProperties- Apply schemas to properties matching patternsadditionalProperties- Apply schema to remaining propertiespropertyNames- Validate property name strings
unevaluatedItems- Apply schema to array items not evaluated by other keywordsunevaluatedProperties- Apply schema to object properties not evaluated by other keywords
- Logic Example
- Array Example
- Object Example
Validation Vocabulary
URI:https://json-schema.org/draft/next/vocab/validation
Purpose: Keywords that assert constraints on instance values.
Validation keywords produce boolean assertion results:
Any type:
type- Restricts instance to specific type(s)enum- Instance must equal one of the specified valuesconst- Instance must equal a specific value
minimum/maximum- Inclusive boundsexclusiveMinimum/exclusiveMaximum- Exclusive boundsmultipleOf- Value must be a multiple of specified number
minLength/maxLength- Length constraintspattern- Regular expression match
minItems/maxItems- Size constraintsuniqueItems- Whether elements must be unique
minProperties/maxProperties- Property count constraintsrequired- Array of required property namesdependentRequired- Required properties based on presence of others
Meta-Data Vocabulary
URI:https://json-schema.org/draft/next/vocab/meta-data
Purpose: Annotation keywords that provide metadata about schemas and instances.
Meta-data keywords don’t affect validation but provide information for humans and applications:
title- Short, human-readable titledescription- Longer explanation of purposedefault- Default value for the instancedeprecated- Whether the instance location is deprecatedreadOnly- Value is managed by owning authoritywriteOnly- Value is never present when retrievedexamples- Sample values illustrating usage
Format Annotation Vocabulary
URI:https://json-schema.org/draft/next/vocab/format-annotation
Purpose: Provides semantic information about string values.
The format keyword indicates the format of string instances:
Dates and Times:
date-time- RFC 3339 date-timedate- RFC 3339 full-datetime- RFC 3339 full-timeduration- ISO 8601 duration
email- RFC 5321 email addresshostname- RFC 1123 hostname
ipv4- IPv4 addressipv6- IPv6 address
uri/uri-reference- URI/URI referenceiri/iri-reference- IRI/IRI referenceuuid- UUID stringuri-template- URI template
json-pointer- JSON Pointerrelative-json-pointer- Relative JSON Pointer
regex- Regular expression
Implementations SHOULD provide assertion behavior for format values but may choose to treat them as annotations only.
Content Vocabulary
URI:https://json-schema.org/draft/next/vocab/content
Purpose: Annotate string-encoded data with content information.
Content keywords describe non-JSON data encoded in JSON strings:
contentEncoding- How the string is encoded (e.g., “base64”)contentMediaType- Media type of the content (e.g., “application/json”)contentSchema- Schema for the decoded content
Unevaluated Vocabulary
URI:https://json-schema.org/draft/next/vocab/unevaluated
Purpose: Apply schemas to instance locations not evaluated by other keywords.
This vocabulary contains:
unevaluatedItems- Apply schema to array items not yet evaluatedunevaluatedProperties- Apply schema to object properties not yet evaluated
Creating Custom Vocabularies
Organizations can define custom vocabularies for specialized needs:Extension Keywords
Additional schema keywords MAY be defined by any entity. Extension keywords:- MUST NOT directly modify the operation of standard keywords
- SHOULD NOT directly modify the operation of other extension keywords
- MAY use the “x-” prefix for simple annotation keywords
Keywords beginning with “x-” are implicitly defined as annotation keywords. Their values are collected as annotations and MUST NOT affect validation.
Example Custom Vocabulary
Vocabulary Best Practices
- Do
- Don't
✓ Use URIs to identify vocabularies uniquely✓ Document vocabulary keywords thoroughly✓ Mark vocabularies as required (
true) if implementations must support them✓ Use “x-” prefix for simple annotation-only extensions✓ Test vocabulary compatibility across implementationsExtensibility Model
JSON Schema’s vocabulary system provides a robust extensibility model:- Clear boundaries - Each vocabulary has a specific purpose and URI
- Optional support - Vocabularies can be marked as optional
- Graceful failure - Implementations refuse unknown required vocabularies
- Standard keywords - Core vocabularies provide common functionality
- Custom extensions - Organizations can add domain-specific keywords
This design allows JSON Schema to evolve and adapt to new use cases while maintaining a stable core and ensuring interoperability.