Skip to content

JSON-LD graph names and scoped contexts: one classifier for every reader, and the context in effect at each node #2080

Open

Description

@aaj3f

#2009 gives JSON-LD one @graph classifier and one graph-name resolution order (classify_written_graph_name: a variable, a fromNamed alias, "default", "config", "txn-meta", then expansion against the @context), shared by templates and where. A few readers still resolve graph names on their own, and expansion only looks at part of the context. One item changes what existing documents expand to, so it needs a decision before code; I've marked it.

One classifier:

Scoped contexts and keywords:

  • Graph names resolve against the document's top-level @context only, in templates and where; node-local and scoped (type- or property-scoped) contexts are ignored for @graph values. Expected: the context in effect at the node.
  • Type-scoped contexts propagate into nested nodes, and several types apply in the order written. JSON-LD 1.1 gives a type-scoped context @propagate: false by default, so it applies to the typed node's own properties and not to node objects nested in them; our expander keeps it for the nested nodes too. And a node with several types applies their scoped contexts in the order written, where the spec applies them in lexicographic order of the type terms. Fixing either changes what existing documents expand to. Needs a decision.
    {"@context": {"ex": "http://example.org/",
      "Person": {"@id": "ex:Person", "@context": {"name": "http://schema.org/name"}},
      "Org": {"@id": "ex:Org", "@context": {"name": "http://org.example/name", "@vocab": "http://orgv/"}}},
     "@graph": [{"@id": "ex:p", "@type": "Person", "name": "P", "ex:k": {"@id": "ex:o", "name": "inner-untyped"}},
                {"@id": "ex:o", "@type": ["Org", "Person"], "name": "O", "x": 1},
                {"@id": "ex:q", "@type": ["Person", "Org"], "name": "Q", "x": 1}]}
    The untyped nested ex:o under ex:p expands name to http://schema.org/name (Person's scope), where the spec leaves name undefined there. And ex:q gets http://org.example/name, where the spec gives both ex:o and ex:q Person's name, since Person sorts after Org.
  • A term defined only in a property-scoped context, used outside it, stays a bare key. Inside author below, name and other expand as the scoped context says. The outer name is undefined in the outer context, which has no @vocab, so the spec drops it; the expander keeps the bare key "name", in strict expansion too, and a transaction would write a predicate named name. Drop it as the spec does, or refuse it in strict expansion as an unresolvable key.
    {"@context": {"ex": "http://example.org/",
      "author": {"@id": "ex:author", "@context": {"name": "http://schema.org/name", "@vocab": "http://scoped/"}}},
     "@id": "ex:a", "author": {"@id": "ex:b", "name": "Ann", "other": 1}, "name": "outer"}
  • Unknown @ keywords are a deviation, but the docs call expansion fully compliant. With fix: JSON-LD graph scoping, config integrity and explicit-only SHACL #2009, an unknown keyword-form key on a node is refused, where the JSON-LD 1.1 expansion algorithm drops it. docs/reference/compatibility.md should list that as a deviation.

The two expander items are pre-existing (identical before and after #2009, which doesn't touch context.rs or the scoped-context code); #2009 fixes the one that wrote wrong data silently, a scoped term's @id over an outer prefix staying compact.

Related existing issues: #1993 (above) and #1991, both of which #2009 may close.

From #2009 (Follow-ups: the ["graph", …] form; Datalog rule heads; the #2007 seam; graph names and the top-level @context; type-scoped propagation; property-scoped bare keys) and bplatz's review of #2009.

Activity

  1. added
    bug
    P3
    triage:needs-decision
    area:transact
    on Oct 12, 2026
  2. bplatz commented on Nov 14, 2026

    @bplatz
    Contributor

    A decision on the item "A term defined only in a property-scoped context, used outside it, stays a bare key": the current behavior stays.

    A key or @type that the context maps to no IRI is stored as a plain name by design. Cypher reads and writes the same plain names, so a JSON-LD write and a Cypher query agree with no context at all. This item is one case of that. #2396 documents it as a deviation in docs/reference/compatibility.md ("Plain names, by design", under JSON-LD 1.1) and in docs/concepts/iri-and-context.md.

    So neither dropping the key nor refusing it in strict expansion is planned, and this item can be checked off.

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

    P3area:transactbugtriage:needs-decision

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions