Skip to content

fix(json-ld): refuse an array or map @value with no @json or @vector type - #2408

Merged
bplatz merged 6 commits into
mainfrom
fix/jsonld-structured-value-needs-type
Nov 18, 2026
Merged

bplatz merged 6 commits into
mainfrom
fix/jsonld-structured-value-needs-type

Conversation

@bplatz

@bplatz bplatz commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

A value object whose @value is an array or a map can only be a literal as a JSON literal or a vector. When neither the object nor its term types it @json or @vector, the expander passed it through, and the readers disagreed:

  • A transaction refused it with Unsupported @value type: Array [...], which names no fix.
  • A bulk import and inline shapes dropped the value without an error.

The expander now refuses it, as JSON-LD 1.1 does an invalid value object: invalid @value value: a value object whose @value is an array or a map needs "@type": "@json" (or "@vector" for an array). Every JSON-LD reader goes through the expander, so they all refuse the same documents.

A map typed @vector (or f:embeddingVector) split the readers the same way: a transaction refused it, and a bulk import stored nothing. The expander now admits a vector type for an array only, and the bulk-import adapter refuses any structured @value it has no literal form for, rather than dropping it. A value object typed @id keeps its own message, that its @value must be a string IRI.

This refuses a whole bulk import that an earlier release completed while dropping such values. That is intended: unlike an ill-typed literal, which is valid RDF an import keeps as written (#2227), this value object is invalid JSON-LD with no literal to keep.

Unchanged:

  • A @json term: its whole value becomes the literal before the expander looks at @value.
  • A value object under a @vector term: it takes the term's type.
  • A JSON-LD where pattern: the query parser reads its values itself.

Merging into next

Found in review of #2393, which makes the same change on next (8e5d2f6). The two will conflict when main is merged into next. Steps the merge does not do by itself are marked manual:

  • fluree-graph-json-ld/src/expand.rs: both add holds_structured_value and the check in parse_value_object. Keep next's. There a value object takes no type from its term, so the check reads only the object's own @type, and its message says so. main's check also reads the term's type, which next no longer gives a value object.
    • Manual: carry this PR's two later changes into next's copy, which has the same gaps. holds_structured_value admits @vector and f:embeddingVector for an array only (it takes the value), and the check skips a value object typed @id, which keeps the @id branch's own message.
  • fluree-graph-json-ld/src/adapter.rs: the fallback that refuses a structured @value with no literal form auto-merges. Keep it.
  • fluree-graph-json-ld/src/expand.rs tests: keep both tests. They auto-merge, so this one is easy to miss. Manual: drop the last assertion of structured_value_object_needs_a_json_or_vector_type (a value object under a @vector term takes the term's type). On next that document is refused. The other assertions match "@type": "@json" or "must be a string", which both lines' messages contain once the @id skip is carried over.
  • fluree-db-api/tests/it_jsonld_value_object_coercion.rs: keep both integration tests.
  • docs/reference/compatibility.md: keep this entry, which auto-merges. Manual: drop its "or the term it sits under" clause. Under next's "A JSON-LD value object is taken as written" entry (fix(json-ld): a value object is taken as written #2393), a term no longer types a value object, and the clause would contradict it.

Tests

  • it_jsonld_value_object_coercion::an_untyped_structured_value_object_is_refused: an array and a map @value under an untyped term, and a map typed @vector or f:embeddingVector, through a transaction and through a bulk import. With the expander check and the adapter refusal both removed, the import succeeds.
  • expand::tests::structured_value_object_needs_a_json_or_vector_type: the refused shapes, including a map under @vector, f:embeddingVector or a @vector term; the accepted ones (@json, @vector and f:embeddingVector on an array, and an array under a @vector term); and an array or map typed @id, which keeps the IRI message.
  • adapter::tests::a_structured_value_with_no_literal_form_is_refused: expanded input that never passed the expander, with a map typed as a vector and an array typed xsd:integer, is refused rather than dropped.

…type

A value object whose @value is an array or a map stands for a literal
only as a JSON literal or a vector. Without either type, from the object
or from its term, the expander passed it through: a transaction then
failed with "Unsupported @value type: Array [...]", and the adapter
behind a bulk import and inline shapes dropped the value without an
error.

The expander now refuses such a value object, as JSON-LD 1.1 does an
invalid value object, with a message that names the @type to add. Every
JSON-LD reader goes through it, so all of them refuse the same
documents. A @JSON term is unaffected (its whole value is the literal
before the expander looks at @value), and a value object under a
@vector term still takes the term's type.
The refusal of an untyped array or map @value is worded differently on
next, where a value object takes no type from its term. Match the part
both messages share, '"@type": "@JSON"', so the tests hold when main is
merged into next.
@bplatz bplatz added the bug Something isn't working as expected label Nov 15, 2026

@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.

@bplatz this is the right fix: one check in the expander so every reader refuses the same document, and your merge-into-next notes hold up (one caveat below).

My reading is that this moves bulk import from silently dropping an untyped array or map @value to refusing the whole import, so an import that worked on 4.2.7 can now fail. That sits beside #2227's lenient-import rule, but I think the line holds: an ill-typed literal is valid RDF we can keep as written, while this value object is invalid JSON-LD with no literal to keep. I'd like your confirmation that it's the intended decision.

Two small musts below: a map typed @vector still drops silently in a bulk import, and the compatibility entry needs the repair half we've been putting on main's data-changing JSON-LD fixes.

Full review below:


✅ Approving to unblock: please get the map-under-@vector drop and the repair sentence in before merging. Refusing in the expander is the right altitude, and both new tests fail with the check disabled (mutation-checked on a box); the two musts are a few lines each.

Before merging:

  1. fluree-graph-json-ld/src/expand.rs:550: a map under @vector passes the expander, and a bulk import drops it silently.
  2. docs/reference/compatibility.md:471: add the repair half: an earlier import stored nothing for such a value, so write it again.

Notes:

  • On merging into next: git merge-tree against next conflicts in expand.rs (take next's side, as you say) and in the integration tests (keep both), but compatibility.md and the expand.rs unit tests auto-merge. So nothing stops a merger from missing your "drop the last assertion" step, after which that test fails on next. And main's compatibility entry, kept verbatim there, says "the term it sits under" can type a value object @vector, which next's own entry from #2393 contradicts. On next I'd drop that clause, or the entry, since #2393's says it already.
  • This is one instance of a shape we keep fixing: one JSON-LD concept read by several readers, each with its own fallback, so one reader drops what another refuses (#2227 for ill-typed literals, #2393 on next, #2414's reserved-predicate checks). Putting the check in the expander is the class fix for this concept. The adapter's own silent fallback is the one site left outside it, which is must 1.
  • The refusal names the fix but not the place: in an NDJSON import it doesn't say which line or node. #2414 threads a path into parse_value_object, so whichever of the two lands second could put it in the message.
  • It merges cleanly onto current main (with my #2227 and #2214) and alongside #2414 and #2425. Claude built all three merged on a box, and the new test passes there.
Adherence: Patterns ✔ · Performance ✔ · Deployment targets ✔ · Testing ✔ · Conventions ⚠️ · verification
  • Patterns/abstractions: ✔ One check in the shared expander rather than one per reader. The adapter's silent fallback is the remaining per-reader path (must 1).
  • Performance (speed first, memory second): ✔ Parser-only: one kind test per value object. No performance-degradation risk.
  • Deployment targets: ✔ n/a: the expander runs the same in every host, and nothing here touches I/O, threads or time.
  • Testing: ✔ Both tests run in CI (grp_transact, fluree-graph-json-ld unit tests) and both fail with the check disabled. The map-under-@vector case has no test yet.
  • Conventions: ⚠️ Multi-line commits, CI green. The Behavior-changes entry lacks the repair half (must 2).

Verified at 56c71d37b: CI green on this SHA (test 16,199 passed incl. both new tests, clippy, fmt, testsuite-sparql, wasm32); on a box Claude ran eleven value-object shapes through a transaction and a bulk import at base and head, disabled the check (both new tests fail), ran merge-tree against next and current main, and built main with #2408, #2414 and #2425 merged.

Approving so you can merge once those two are in.

Comment thread fluree-graph-json-ld/src/expand.rs Outdated

/// Whether a value object typed `type_iri` may hold an array or a map: a JSON
/// literal, or a vector (an array only, which the vector parser checks).
fn holds_structured_value(type_iri: Option<&str>) -> bool {

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.

Blocking: a map typed @vector still drops silently in a bulk import.

holds_structured_value admits @vector and f:embeddingVector for any structured @value, on the strength of the vector parser refusing a map (the comment above it). A transaction does refuse it ("Cannot coerce object to …embeddingVector"). But a bulk import never reaches a vector parser: the adapter's Value::Object(_) | Value::Array(_) arm keeps only an array under the vector type, and everything else falls to Ok(ProcessedValue::None) under "shouldn't happen".

Claude ran {"@id": "ex:s", "ex:v": {"@value": {"a": 1}, "@type": "@vector"}} (and the f:embeddingVector spelling) at this head: the transaction refuses it, and the bulk import succeeds with 0 flakes, the value gone. So that one document still splits the readers, the way the untyped ones did before this PR.

Either fix is small. Admitting the vector types for arrays only:

fn holds_structured_value(type_iri: Option<&str>, val: &JsonValue) -> bool {
    match type_iri {
        Some("@json" | fluree_vocab::rdf::JSON) => true,
        Some("@vector" | fluree_vocab::fluree::EMBEDDING_VECTOR) => val.is_array(),
        _ => false,
    }
}

Or (my preference, since it also covers whatever the expander lets through next) turning the adapter's fallback into an AdapterError::InvalidStructure naming the datatype, so no reader can drop a structured @value silently. next's copy of holds_structured_value from #2393 has the same gap, so whichever you pick wants to land on both lines. Commenting here because adapter.rs is not in this diff.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 49cb18d — both: the expander admits the vector types for an array only, and the adapter's fallback refuses a structured @value it has no literal form for instead of dropping it. The merge notes in the PR body now say to carry the array-only rule into next's copy.

Comment thread docs/reference/compatibility.md Outdated

#### A JSON-LD array or map `@value` needs a `@json` or `@vector` type

A value object whose `@value` is an array or a map is refused unless it, or the term it sits under, types it `@json` or `@vector`: `{"@value": [0.5, 0.25]}` under an untyped term has no literal to stand for. A transaction refused it already, with a message that named no fix, and a bulk import and inline shapes dropped the value without an error. Each now refuses it with a message that names the `@type` to add.

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.

Blocking (D1's floor): the entry needs its repair half.

The entry says what a new document gets. It doesn't say what an earlier release left behind: a bulk import or inline shape that held such a value stored nothing for it, and nothing in the ledger records the drop. The data-changing JSON-LD fixes we've shipped on main carry a Behavior-changes entry and a repair recipe, and here the recipe is a sentence. Something like:

Suggested change
A value object whose `@value` is an array or a map is refused unless it, or the term it sits under, types it `@json` or `@vector`: `{"@value": [0.5, 0.25]}` under an untyped term has no literal to stand for. A transaction refused it already, with a message that named no fix, and a bulk import and inline shapes dropped the value without an error. Each now refuses it with a message that names the `@type` to add.
A value object whose `@value` is an array or a map is refused unless it, or the term it sits under, types it `@json` or `@vector`: `{"@value": [0.5, 0.25]}` under an untyped term has no literal to stand for. A transaction refused it already, with a message that named no fix, and a bulk import and inline shapes dropped the value without an error. Each now refuses it with a message that names the `@type` to add. A ledger built by an earlier bulk import holds nothing for such a value, and nothing records that it was dropped: to restore one, write it again with the `@type` it needs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 66f7aff

Comment thread fluree-graph-json-ld/src/expand.rs Outdated
_ => None,
}),
};
if (val.is_array() || val.is_object()) && !holds_structured_value(type_iri.as_deref()) {

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.

This is more of a nit than a must. Because the new check runs before the @id branch, {"@value": ["ex:a"], "@type": "@id"} now gets "needs "@type": "@json" (or "@vector" for an array)" where it got "a value object typed @id names an IRI, so its @value must be a string" (Claude compared the two on a box). The old message names the real fix. Skipping the structured check when type_iri is @id keeps it. It's minor and non-blocking, but if you agree it's right, I'd rather see it folded in now than lost in the backlog.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in bfb4cf8

… adapter

The expander let a value object typed `@vector` (or
`f:embeddingVector`) hold any array or map, on the strength of the
vector parser refusing a map. A transaction reaches that parser; a bulk
import does not. The adapter keeps only an array under the vector type,
and its fallback for any other array or map `@value` returned no value,
so the import stored nothing for the map and raised no error.

The expander now admits a vector type for an array only, so a map typed
as a vector fails every reader with the same message, naming the type
to use. The adapter's fallback is an error too: a structured `@value`
it has no literal form for, in expanded input that never passed the
expander, is refused with the datatype it carried rather than dropped.

Tests cover the map under `@vector`, under `f:embeddingVector` and
under a `@vector` term in the expander; the adapter's refusal on
expanded input; and both spellings through a transaction and a bulk
import.
… dropped

The entry said what a new document gets but not what an earlier release
left behind: a bulk import or inline shape that held an untyped array
or map `@value`, or a map typed `@vector`, stored nothing for it, and
nothing in the ledger records the drop. It now says so, and that the
value is restored by writing it again with the `@type` it needs.

It also says `@vector` types an array only, as the expander now checks.
The structured-value check ran before the `@id` branch, so
`{"@value": ["ex:a"], "@type": "@id"}` was told it needs
`"@type": "@JSON"`, where it used to be told that a value object typed
`@id` names an IRI and its `@value` must be a string. The second names
the real fix. The check now leaves a value object typed `@id` to that
branch.
@bplatz

bplatz commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

From the review summary:

Bulk import now refuses the whole import where 4.2.7 dropped the value; please confirm that's intended.

Confirmed, it's intended: an ill-typed literal is valid RDF an import keeps as written (#2227), while this value object is invalid JSON-LD with no literal to keep. The PR body now says so.

Merging into next: the dropped assertion is easy to miss, and the compatibility entry's term clause contradicts #2393's.

Addressed in the PR body's "Merging into next" section, which marks each manual step: drop that assertion, drop the "or the term it sits under" clause, and carry the array-only @vector rule and the @id skip into next's copy of the check.

The refusal doesn't name the NDJSON line or node.

Noted on #2414, so whichever lands second adds the path: #2414 (comment)

@bplatz
bplatz merged commit 49a1967 into main Nov 18, 2026
21 checks passed
@bplatz
bplatz deleted the fix/jsonld-structured-value-needs-type branch November 18, 2026 17:32
bplatz added a commit that referenced this pull request Nov 18, 2026
Brings #2408 and #2366.

#2408 and next's #2393 each add the structured-value check to the
expander. Next's is kept, as #2408's merge notes say: a value object
takes no type from its term there, so the check reads only the object's
own `@type`. #2408's two later changes are carried into it: a vector
type admits an array only (a map typed `@vector` was dropped by a bulk
import), and a value object typed `@id` keeps its own message that its
`@value` must be a string IRI. The adapter's refusal of a structured
`@value` with no literal form merged as is.

Both expander tests are kept; #2408's loses its last assertion, that a
value object under a `@vector` term takes the term's type, which next
refuses. Both integration tests are kept. #2408's compatibility entry
drops "or the term it sits under", which would contradict next's
"A JSON-LD value object is taken as written".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants