Skip to content

fix: do not compact JSON-LD @id node identifiers against @vocab - #1284

Merged
bplatz merged 1 commit into
mainfrom
fix/id-resolution
Jun 3, 2026
Merged

bplatz merged 1 commit into
mainfrom
fix/id-resolution

Conversation

@bplatz

@bplatz bplatz commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Per JSON-LD 1.1, @vocab governs only property names, @type values, and @type: @vocab term values — it must not shorten node identifiers. The result formatters were compacting @id positions through the @vocab path, so with a query @context of {"@vocab": "http://example.org/lists/"} an @id of http://example.org/lists/summer was emitted as the bare term "summer", which a conformant processor re-resolves against @base, not @vocab.

Changes

  • Add IriCompactor::compact_id_sid (decode then @id-position compaction: @base + explicit prefixes only, never @vocab).
  • Route every @id / node-reference output site through the compact_id_* path:
    • hydration.rs: root @id, expand_ref bare-@id fallback, nested-ref @id, reverse-value @id, and the defensive Ref-in-literal @id fallbacks
    • jsonld.rs: flat-select Binding::Sid / IriMatch
    • typed.rs: Binding::Sid / IriMatch
    • sparql.rs: SPARQL JSON uri value (a uri is a node identifier too)
  • Predicate keys, @type values, datatype @type, and reverse-predicate keys keep the @vocab path. construct.rs was already correct; agent_json.rs inherits the fix via its jsonld delegation.

Behavior preserved

compact_vocab intentionally keeps @base as a fallback vocabulary so a bare @type/predicate in an @base-only context round-trips — unchanged. @vocab: "" still maps the vocabulary to @base.

Tests & docs

  • Unit tests (iri/jsonld/typed) plus an integration suite covering the hydration root and nested @id, flat-select references, combined @base+@vocab separation, and the @vocab: "" → @base round-trip.
  • Documented the @vocab/@base compaction rules in docs/concepts/iri-and-context.md.

Closes: #1280

Per JSON-LD 1.1, @vocab governs only property names, @type values, and
@type:@vocab term values. It must not shorten node identifiers. The result
formatters were compacting @id positions through the @vocab path, so with a
query @context of {"@vocab": "http://example.org/lists/"} an @id of
http://example.org/lists/summer was emitted as the bare term "summer" — which
a conformant processor re-resolves against @base, not @vocab.

Add IriCompactor::compact_id_sid (decode then @ID-Position compaction: @base
and explicit prefixes only, never @vocab) and route every @id / node-reference
output site through the compact_id_* path:

- hydration.rs: root @id, expand_ref bare-@id fallback, nested-ref @id,
  reverse-value @id, and the defensive Ref-in-literal @id fallbacks
- jsonld.rs: flat-select Binding::Sid / IriMatch
- typed.rs: Binding::Sid / IriMatch
- sparql.rs: SPARQL JSON uri value (a uri is a node identifier too)

Predicate keys, @type values, datatype @type, and reverse-predicate keys keep
the @vocab path. construct.rs was already correct; agent_json.rs inherits the
fix via its jsonld delegation.

Note: compact_vocab intentionally keeps @base as a fallback vocabulary so a
bare @type/predicate in an @base-only context round-trips; that behavior is
unchanged. @vocab:"" still maps the vocabulary to @base.

Add unit tests (iri/jsonld/typed) and an integration suite covering the
hydration root and nested @id, flat-select references, combined @base+@vocab
separation, and the @vocab:"" -> @base round-trip. Document the @vocab/@base
compaction rules in docs/concepts/iri-and-context.md.
@bplatz
bplatz requested review from aaj3f and zonotope June 3, 2026 17:26

@aaj3f aaj3f left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is admittedly trivial but your description says

Route every @id / node-reference output site through the compact_id_* path

Claude noted that this is not still true for CSV/TSV delimited output paths. Otherwise all good!

@bplatz
bplatz merged commit c383484 into main Jun 3, 2026
13 of 14 checks passed
@bplatz
bplatz deleted the fix/id-resolution branch June 3, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON-LD formatter compacts @id against @vocab (should only use @base / explicit prefixes)

2 participants