W3C home > Mailing lists > Public > public-rdf-comments@w3.org > September 2012

RE: XSD datatypes in JSON-LD (was: Re: Use of XSD namespace in RDF recommendations)

From: Markus Lanthaler <markus.lanthaler@gmx.net>
Date: Wed, 5 Sep 2012 14:28:54 +0200
To: "'Richard Cyganiak'" <richard@cyganiak.de>
Cc: "'Gregg Kellogg'" <gregg@greggkellogg.net>, "'public-rdf-comments Comments'" <public-rdf-comments@w3.org>
Message-ID: <011601cd8b62$0a576d10$1f064730$@lanthaler@gmx.net>
On Wednesday, September 05, 2012 12:51 PM, Richard Cyganiak wrote:

> TIL that every number is a double in JS.

True. There doesn't exist such a thing as an integer type in
JSON/JavaScript. Basically all numbers are doubles.

> I guess it's not possible to round-trip idiomatic RDF numbers through
> idiomatic JSON. Oh well.

Yeah.. this has been one of the pain points while creating the spec.

> What is the justification then for treating the JSON literal 5 as
> "5"^^xsd:integer in toRDF, rather than as "5"^^xsd:double? The latter
> seems to be the accurate translation.

I would certainly be fine with just translating all JSON numbers to
xsd:double but what should we do with xsd:integer in fromRDF() then? Keep it
as string? Or convert it to a JSON number? If we do that, and I think we
should, we would "break" round-tripping as we effectively transalte from
xsd:integer to xsd:double.

Splitting JSON numbers into xsd:integer/xsd:double was kind of a compromise
to have a lossless round-trip *most* of the time. It doesn't work perfectly

> Another issue I suppose is that xsd:double contains the values NaN, INF
> and -INF, which are not valid as JSON numbers and hence cannot be
> round-tripped if native JSON numbers are used.

Exactly. Therefore, if conversion to a native number fails, we keep the
value in expanded form.

Markus Lanthaler
Received on Wednesday, 5 September 2012 12:29:35 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:29:54 UTC