Re: Duplicate JSON Object Keys

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: "David E(dot) Wheeler" <david(at)justatheory(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Duplicate JSON Object Keys
Date: 2013-03-07 20:04:02
Message-ID: 5138F2B2.4000603@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 03/07/2013 02:48 PM, David E. Wheeler wrote:
> This behavior surprised me a bit:
>
> david=# select '{"foo": 1, "foo": 2}'::json;
> json
> ----------------------
> {"foo": 1, "foo": 2}
>
> I had expected something more like this:
>
> david=# select '{"foo": 1, "foo": 2}'::json;
> json
> ------------
> {"foo": 2}
>
> This hasn’t been much of an issue before, but with Andrew’s JSON enhancements going in, it will start to cause problems:
>
> david=# select json_get('{"foo": 1, "foo": 2}', 'foo');
> ERROR: field name is not unique in json object
>
> Andrew tells me that the spec requires this. I think that’s fine, but I would rather that it never got to there.

Specifically, rfc4627 says (note last sentence):

2.2. Objects

An object structure is represented as a pair of curly brackets
surrounding zero or more name/value pairs (or members). A name is a
string. A single colon comes after each name, separating the name
from the value. A single comma separates a value from a following
name. The names within an object SHOULD be unique.

cheers

andrew

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2013-03-07 21:45:25 Re: Enabling Checksums
Previous Message Kevin Grittner 2013-03-07 19:50:11 Re: REFRESH MATERIALIZED VIEW locklevel