Skip to main content
The $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

string
required
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:
  1. Schema Identification: Provides a unique identifier for the schema resource
  2. Base IRI Establishment: Sets the base IRI for resolving relative references in the schema
  3. Reference Target: Allows other schemas to reference this schema by IRI
  4. 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:
The embedded 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:
Resolved IRIs:
  • address.json → https://example.com/schemas/address.json
  • types/contact.json → https://example.com/schemas/types/contact.json

IRI Resolution

Base IRI Determination

The base IRI for resolving $id values is determined by:
  1. Explicit $id in parent: If a parent schema has $id, it becomes the base IRI
  2. Document retrieval location: The IRI from which the document was retrieved
  3. 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
Base IRIs:
  • Root schema: https://example.com/foo
  • Embedded items schema: https://example.com/bar
  • additionalProperties schema: https://example.com/bar (inherits from parent)

Examples

Schema with References

  • #item resolves to https://example.com/root.json#item
  • other.json resolves to https://example.com/other.json

Network-Addressable vs Non-Addressable IRIs

The $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:
Use $anchor or $dynamicAnchor to create fragment identifiers within a schema resource.
  • $schema - Declares the schema dialect
  • $ref - References schemas by IRI
  • $anchor - Creates plain name fragment identifiers
  • $defs - Common location for reusable schemas