Re: Proposal: Add JSON support

Поиск
Список
Период
Сортировка
От Joseph Adams
Тема Re: Proposal: Add JSON support
Дата
Msg-id m2qe7e5fefd1004052050pf99c54b3pb315256a812e279c@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Proposal: Add JSON support  (Andrew Dunstan <andrew@dunslane.net>)
Ответы Re: Proposal: Add JSON support
Re: Proposal: Add JSON support
Re: Proposal: Add JSON support
Re: Proposal: Add JSON support
Список pgsql-hackers
Another JSON strictness issue:  the JSON standard (
http://www.ietf.org/rfc/rfc4627.txt ) states that JSON text can only
be an array or object.  However, my implementation currently accepts
any valid value.  Thus, '3', '"hello"', 'true', 'false', and 'null'
are all accepted by my implementation, but are not strictly JSON text.The question is: should the JSON datatype accept
atomicvalues (those
 
that aren't arrays or objects) as valid JSON?

I tried a few other JSON implementations to see where they stand
regarding atomic types as input:

JSON_checker (C) does not accept them.
JSON.parse() (JavaScript) accepts them.
json_decode() (PHP) accepts them.  However, support is currently buggy
(e.g. '1' is accepted, but '1 ' is not).
cJSON (C) accepts them.
JSON.pm (Perl) accepts them if you specify the allow_nonref option.
Otherwise, it accepts 'true' and 'false', but not 'null', a number, or
a string by itself.

In my opinion, we should accept an atomic value as valid JSON content.I suppose we could get away with calling it a
"content"fragment as
 
is done with XML without a doctype.

Accepting atomic values as valid JSON would be more orthagonal, as it
would be possible to have a function like this:

json_values(object_or_array JSON) RETURNS SETOF JSON
-- extracts values from an object or members from an array, returning
them as JSON fragments.

Also, should we go even further and accept key:value pairs by themselves? :

'"key":"value"'::JSON

I don't think we should because doing so would be rather zany.  It
would mean JSON content could be invalid in value context, as in:

// JavaScript
var content = "key" : "value";

I improved my JSON library.  It now only accepts strict, UTF-8 encoded
JSON values (that is, objects, arrays, strings, numbers, true, false,
and null).  It also has a json_decode_liberal() function that accepts
a string, cleans it up, and passes it through the stricter
json_decode().  json_decode_liberal() filters out comments, allows
single quoted strings, and accepts a lax number format compared to
strict JSON.  I may add Unicode repair to it later on, but
implementing that well really depends on what type of Unicode errors
appear in real life, I think.

http://constellationmedia.com/~funsite/static/json-0.0.2.tar.bz2

My json.c is now 1161 lines long, so I can't quite call it "small" anymore.


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: [SPAM]Re: Questions about 9.0 release note
Следующее
От: Robert Haas
Дата:
Сообщение: Re: Proposal: Add JSON support