Skip to content

JSON-LD adapter labels a native number or boolean @value with no @type as xsd:string #2211

Closed

Description

@aaj3f

I tripped over this while building a request body out of fluree doc parse output, and it seems worth fixing on its own.

process_literal in fluree-graph-json-ld/src/adapter.rs:623-631 defaults the datatype to xsd:string whenever a value object has no @type, including when the @value is a native JSON number or boolean. The value itself is kept native (LiteralValue::Integer(0)), so what reaches the sink is a literal that says it's a string but holds an integer. That's exactly what expansion produces for a bare 0, 1.5 or true: {"doc:columnIndex": 0} expands to [{"@value": 0}] with no @type.

The two database sinks (flake_sink, import_sink) infer the datatype from the value and ignore the declared one, so I don't think transactions or bulk import have ever stored anything wrong because of this. But a sink that keeps the datatype does notice. GraphCollectorSink builds a Graph whose term reads Literal { value: Integer(0), datatype: xsd:string }, and fluree_graph_format::format_ntriples then writes it as "0", a plain string. A strict consumer of that N-Triples refuses it (the one I hit answered doc:columnIndex must be an xsd:integer). The direct-scalar path a few lines below (Value::Number outside a value object, adapter.rs:574) already types these as xsd:integer / xsd:double / xsd:boolean, so the two paths disagree today.

A minimal repro:

let expanded = json!([{ "@id": "urn:a", "urn:p": [{ "@value": 0 }] }]);
let mut sink = GraphCollectorSink::new();
to_graph_events(&expanded, &mut sink).unwrap();
// object: Literal { value: Integer(0), datatype: xsd:string } → format_ntriples writes "0"

The fix seems small. When there's no @type, give a native value the datatype JSON-LD's RDF conversion gives it: xsd:boolean for a boolean, xsd:integer for an integral number, xsd:double otherwise (the same rule the direct-scalar path uses), and xsd:string only for a string. The callers I found are fluree-db-transact/src/import.rs (bulk import, through import_sink, which infers from the value), fluree-db-api/src/{inline_shapes,inline_ontology}.rs (through GraphCollectorSink), and splitter.rs's doc example. template_sink, which hashes by the declared datatype, is only fed by the Turtle/TriG parser, so its hashes shouldn't move. I have a PR for this coming.

One nuance I'm leaving alone: JSON-LD would call 5.0 an xsd:integer (no fractional part), but serde reads it as an f64, so both paths type it xsd:double. That's consistent with what the direct-scalar path already does, so I'd rather not change it in the same fix.

Activity

  1. self-assigned this
    on Oct 29, 2026
  2. added
    bug
    P3
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions