W3C home > Mailing lists > Public > public-linked-json@w3.org > November 2014

Re: "in #JSON-LD the keys in objects must be unique" -- why?

From: Niklas Lindström <lindstream@gmail.com>
Date: Sat, 22 Nov 2014 15:28:02 +0100
Message-ID: <CADjV5jfKrrB2=Mv6tUUj8G5no4o2L6K3TEvpYgnm7p+tUdvySg@mail.gmail.com>
To: François-Paul Servant <francoispaulservant@gmail.com>
Cc: "public-linked-json@w3.org" <public-linked-json@w3.org>
This is because JSON itself does not, in practice, support multiple keys
with the same name. Specifically, the RFC [1] says "the names within an
object SHOULD be unique", but implementations commonly throw away all but
the last value (see e.g. [2] and [3]). This implementation behavior makes
it basically impossible for JSON-LD parsers relying on an underlying JSON
parser from detecting and warning about it, unless the underlying parser
has support for that.

To overcome this mismatch between the JSON and RDF data models, JSON-LD
handles arrays of values as sets of predicate, value pairs, and instead has
a special construct, @list, to explicitly provide a way of representing
closed, ordered RDF collections. You can also control this in compact form
by using the @container feature with the @set and @list keywords. See the
JSON-LD Syntax [4] for the details.

I hope this makes you less disappointed. :)

Cheers,
Niklas

[1]: http://www.ietf.org/rfc/rfc4627.txt
[2]:
http://stackoverflow.com/questions/21832701/does-json-syntax-allow-duplicate-keys-in-an-object
[3]:
http://stackoverflow.com/questions/5306741/do-json-keys-need-to-be-unique
[4]: http://www.w3.org/TR/json-ld/#sets-and-lists


On Sat, Nov 22, 2014 at 2:55 PM, François-Paul Servant <
francoispaulservant@gmail.com> wrote:

> As I am a bit disappointed by the fact that keys in JSON-LD objects must
> be unique, I've tried to understand why it is so (as keys are properties, I
> didn't expect such a restriction - I know that we can use an array for
> multi-valued properties, but I would have expected that repeating a key
> would just have added more values - more triples to the graph). I've not
> been able to find an explanation (I tried searching this list without
> result, but I may have missed it). Could someone point me to some
> explanation / discussion on the topic? (it seems to me that I would be less
> disappointed if I understood why things are the way they are)
>
> BTW, If you pass some JSON-LD that does not respect this rule to the
> playground (OK, not JSON-LD, then), you don't get any error or warning
> message (it seems that the latest value is used in the result)
>
> Best,
>
> fps
>
>
>
Received on Saturday, 22 November 2014 14:29:00 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:18:42 UTC