Skip to content

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

Closed

Description

@bplatz

Summary

When a query @context defines an @vocab, the JSON-LD result formatter compacts @id node identifiers against that @vocab, producing a bare term. Per JSON-LD 1.1, @vocab governs only properties, @type values, and values of @type: @vocab terms — it must not be used to compact node identifiers. Only @base and explicit term/prefix/@id-term mappings apply to @id.

Example

Given a subject http://example.org/lists/summer and a query context:

{ "@context": { "@vocab": "http://example.org/lists/" }, ... }

The formatter currently emits:

{ "@id": "summer" }

summer round-trips only because it happens to match @vocab, but it is non-conformant: a compliant JSON-LD processor expanding summer as an @id would resolve it against @base (or leave it relative), not against @vocab. Expected output is the full IRI (or a compaction via an explicit prefix / @base-relative form):

{ "@id": "http://example.org/lists/summer" }

Root cause

The codebase already distinguishes the two compaction modes:

  • IriCompactor::compact_id / IriCompactor::compact_id_iri — correct for @id (no @vocab).
  • IriCompactor::compact_vocab / compact_vocab_iri / compact_iri / compact_sid — for predicates and @type (applies @vocab).

fluree-db-api/src/format/construct.rs already routes @id through the vocab=false path correctly. But the hydration / jsonld / typed formatters use the vocab-applying methods for @id positions:

  • fluree-db-api/src/format/hydration.rs — root @id (compact_iri / compact_sid) and bare-@id fallback (compact_iri).
  • fluree-db-api/src/format/jsonld.rs — Binding::Sid and Binding::IriMatch @id output (compact_sid / compact_iri).
  • fluree-db-api/src/format/typed.rs — Binding::Sid and Binding::IriMatch @id output.

These should route through compact_id (the @id-position method) instead, matching construct.rs.

Scope / impact

  • Affects single-ledger and multi-ledger formatting equally; surfaced while reviewing the multi-ledger work in fix: multi-ledger JSON-LD queries through /v1/fluree/query (dispatcher + formatter) #1267 but is independent of it.
  • Only manifests when the query @context sets @vocab and a result @id falls under that vocab namespace.
  • Fix is localized (swap the compaction method at @id call sites) but needs care: compact_sid both decodes the SID and compacts, so the @id paths need a decode-then-compact_id variant.

Suggested regression coverage

Add a formatter test asserting that with @vocab set, a result @id whose IRI falls under the vocab namespace is not reduced to a bare term (expect the full IRI, or an explicit-prefix / @base-relative compaction).

Activity

  1. added
    bug
    on Jun 3, 2026
  2. added a commit that references this issue on Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions