w3c / w3c/json-ld-syntax

Elaborate on handling of JSON builtin types `integer` and `double`

Open
#387 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Editorial editorial:class 2 Errata
Dominant language
HTML
Stars
139
Forks
23
PR merge metrics
No merged PRs in 30d

Description

The spec doesn't describe explicitly enough what happens with JSON builtin types integer and double.

  1. By using a native JSON type such as number, true, or false.
  • https://w3c.github.io/json-ld-syntax/#type-coercion talks about converting strings, not numerics
  • #335 describes an unpleasant situation where an integer (eg 3 instead of "3") cannot be used in URL
  • this example at the playground produces ex:pi "3.14E0"^^xsd:double (ok) but ex:two "2"^^xsd:integer ?!?!?
{"@context":{"@vocab":"http://example.org/"},
  "pi": 3.14, "two": 2.0000000000000001}
  • remove one decimal zero and you get ex:two "2.000000000000001E0"^^xsd:double which means the datatype varies with the lexical precision
  • In contrast, Turtle is consistent: 2.0 and 2.0000000000000001 mean xsd:decimal

@msporny @gkellogg
I think the spec should be more explicit what implicit conversions are applied to JSON builtin types, and give some warnings about the examples above.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the JSON-LD 1.1 sections on typed values and type coercion, then review issue #335 and reproduce the linked playground examples for integer and double values. Clarify the implicit conversions and lexical-precision behavior, add explicit specification text and warnings, and update the examples so the resulting datatypes are unambiguous.

Written by the indexing model from the issue text.

Assessment

Tech stack
json
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.