json-ld-api icon indicating copy to clipboard operation
json-ld-api copied to clipboard

RDF to Object Conversion drops type values if useNativeTypes is set to true

Open niklasl opened this issue 2 months ago • 2 comments

In the JSON-LD 1.1 RDF to Object Conversion algorithm (8.5), step 2.4 says "If useNativeTypes is true", then steps into a nested set of steps. This is then followed by "Otherwise, if" steps 2.5-2.8.

This seems like a spec bug, since only if the value is actually converted within the nested checks of 2.4 should that step be considered complete. As it stands, step 2.5-2.8 will be ignored if useNativeTypes is set to true, resulting in {"@value": ...} objects with no @type at all.

If implemented verbatim (such as in TRLD), this will not properly convert the literals in this N-quads data:

<http://example.com> <http://example.com/property> "string" .
<http://example.com> <http://example.com/property> "hello"@en .
<http://example.com> <http://example.com/property> "No"^^<http://www.w3.org/2001/XMLSchema#boolean> .
<http://example.com> <http://example.com/property> "AAA"^^<http://www.w3.org/2001/XMLSchema#double> .
<http://example.com> <http://example.com/property> "{\"x\": 1}"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#JSON> .

I will prepare a PR with a spec fix and additional tests for this problem.

niklasl avatar Nov 18 '25 16:11 niklasl

Good catch!

TallTed avatar Nov 18 '25 19:11 TallTed

Thank you for looking into this! I think I might be the author of the bug. I'll also check it out but not sure how soon I can.

anatoly-scherbakov avatar Nov 19 '25 11:11 anatoly-scherbakov