$id keyword identifies a schema or subschema as a distinct schema resource and establishes the base IRI for resolving relative IRI references within that resource.
Syntax
A string representing a valid IRI reference without a fragment. When resolved against the current base IRI, it becomes the identifier for the schema resource.
Purpose
The$id keyword serves multiple critical functions:
- Schema Identification: Provides a unique identifier for the schema resource
- Base IRI Establishment: Sets the base IRI for resolving relative references in the schema
- Reference Target: Allows other schemas to reference this schema by IRI
- Resource Boundary: Defines embedded schema resources within a document
Usage
Root Schema Identification
The root schema of a JSON Schema document SHOULD contain an$id with an absolute IRI (containing a scheme, but no fragment).
Embedded Resources
When an$id appears in a subschema, it creates a new embedded schema resource with its own identifier:
address schema can be referenced by its IRI: https://example.com/schemas/address.json
Relative IRI References
$id can use relative IRI references, which are resolved against the current base IRI:
address.json→https://example.com/schemas/address.jsontypes/contact.json→https://example.com/schemas/types/contact.json
IRI Resolution
Base IRI Determination
The base IRI for resolving$id values is determined by:
- Explicit
$idin parent: If a parent schema has$id, it becomes the base IRI - Document retrieval location: The IRI from which the document was retrieved
- Implementation default: Implementation-specific default base IRI
Resolving the $id Value
When resolved against the base IRI, the $id value becomes:
- The canonical identifier for the schema resource
- The new base IRI for any nested schemas or references
- Root schema:
https://example.com/foo - Embedded
itemsschema:https://example.com/bar additionalPropertiesschema:https://example.com/bar(inherits from parent)
Examples
Schema with References
#itemresolves tohttps://example.com/root.json#itemother.jsonresolves tohttps://example.com/other.json
Network-Addressable vs Non-Addressable IRIs
$id is an identifier, not necessarily a network locator. A schema need not be downloadable from its canonical IRI. URN-based identifiers are valid and useful for schemas not intended for network retrieval.
Important Notes
Empty IRI Fragment
An$id consisting of an empty IRI will result in the embedded resource having the same IRI as its parent, which SHOULD be considered an error.
Duplicate Schema Identifiers
When multiple schemas attempt to identify as the same IRI through$id, $anchor, or other mechanisms, implementations SHOULD raise an error. The result is otherwise undefined and not interoperable.
Fragment Identifiers
The$id value MUST NOT contain a fragment identifier:
$anchor or $dynamicAnchor to create fragment identifiers within a schema resource.