json_get() Throws Error on object with duplicate keys

Issue #3 resolved
David Wheeler created an issue

Example:

david=# select json_get('{"foo": 1, "foo": 2}', 'foo');
ERROR:  field name is not unique in json object

I don't think it should do that. Here's the corresponding example in JavaScript:

javascript:alert({"foo": 1, "foo": 2}.foo)

Which yields 2, which is what I would expect. It works like a Perl hash in this way: later keys override earlier instances of the same keys.

But I'm thinking that this might be an issue to bring up for the core JSON object. I think there's an argument to be made that this:

david=# select '{"foo": 1, "foo": 2}'::json;
         json         
----------------------
 {"foo": 1, "foo": 2}

Really ought to be this:

david=# select '{"foo": 1, "foo": 2}'::json;
    json    
------------
 {"foo": 2}

Thoughts?

Comments (1)

  1. Log in to comment