Fragment Identifier Types
JSON Pointer Fragments
Fragment identifiers that start with
/ or are the empty string. Structural, location-based references.Plain Name Fragments
All other fragment identifiers. Location-independent references defined by
$anchor.JSON Pointer Fragment Identifiers
The use of JSON Pointers as IRI fragment identifiers is described in RFC 6901. Fragment identifiers that start with/ or are the empty string MUST be interpreted as JSON Pointer fragment identifiers.
Structure-Based References
JSON Pointers navigate the structure of a JSON document using a syntax of slash-separated path segments:https://example.com/schema.json#
https://example.com/schema.json#
Empty fragment - references the entire root schema
https://example.com/schema.json#/properties/name
https://example.com/schema.json#/properties/name
References the “name” property schema (type: string)
https://example.com/schema.json#/$defs/address
https://example.com/schema.json#/$defs/address
References the “address” definition in $defs
https://example.com/schema.json#/$defs/address/properties/city
https://example.com/schema.json#/$defs/address/properties/city
References the “city” property within the address definition
Limitations of JSON Pointers
Consider this schema with an embedded resource:https://example.com/foo#/items/additionalProperties points to the correct object, but:
- It’s relative to the “foo” resource’s base IRI
- If the embedded “bar” resource is extracted to a separate document, this reference breaks
- The canonical IRI relative to “bar” is
https://example.com/bar#/additionalProperties
https://example.com/foo#/items/additionalProperties no longer resolves correctly.
Applications and schemas SHOULD NOT use JSON Pointer IRIs to identify embedded schema resources or locations within them. Use plain name fragments with
$anchor instead for location-independent references.Plain Name Fragment Identifiers
Plain name fragment identifiers are reserved for referencing locally named schemas. All fragment identifiers that are not interpreted as JSON Pointers MUST be interpreted as plain name fragment identifiers.Defining Plain Name Fragments with $anchor
Defining a plain name fragment identifier within a schema resource is done using the $anchor keyword.
The value of $anchor MUST be a string conforming to the NCName production:
- Must start with a letter or underscore
- Can contain letters, digits, underscores, hyphens, and periods
- No spaces or special characters
Location-Independent References
Plain name fragments provide location-independent identification. A subschema can be relocated without requiring references to be updated:#product-id remain valid even if:
- The definition is moved to a different location in
$defs - The definition is moved to a different schema object
- The schema is restructured
Benefits of Plain Name Fragments
Stability
References don’t break when schema structure changes
Readability
Semantic names like
#user-address are clearer than #/$defs/schemas/addressPortability
Subschemas can be moved between documents without updating references
Intent
Makes it clear which subschemas are intended for reuse
Fragment Identifier Examples
Consider this comprehensive schema:Valid References
- Document Root
- $defs/A
- $defs/B
- $defs/B/$defs/X
- $defs/B/$defs/Y
- $defs/C
- Canonical IRI:
https://example.com/root.json - With pointer fragment:
https://example.com/root.json#
References to Avoid
These IRIs technically work but should be avoided because they reference across resource boundaries: These references are fragile and may not work in all implementations, especially if the schemas are later separated into different documents.Best Practices
Use $anchor for reusable schemas
Define anchors for any subschema you expect to reference multiple times or that represents a stable concept.
Avoid JSON Pointer fragments across resource boundaries
Don’t use JSON Pointer fragments to reference into embedded schema resources. Use the embedded resource’s canonical IRI instead.
Choose semantic anchor names
Use descriptive names like
user-profile or email-address rather than generic names like def1 or schema-a.Next Steps
Schema Structure
Learn about schema composition and references
Core Keywords
Explore the
$id, $anchor, and $ref keywords