Re: [HACKERS] Proposal: Add JSON support

2010-04-06 Thread Petr Jelinek
Dne 6.4.2010 7:57, Joseph Adams napsal(a): On Tue, Apr 6, 2010 at 1:00 AM, Petr Jelinekpjmo...@pjmodos.net wrote: Not really sure about this myself, but keep in mind that NULL has special meaning in SQL. To me, the most logical approach is to do the obvious thing: make JSON's 'null'

Re: [HACKERS] Proposal: Add JSON support

2010-04-06 Thread Alvaro Herrera
Joseph Adams escribió: 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. Just noticed you don't check the return value of malloc and friends. How do you intend to handle that? There are various places

Re: [HACKERS] Proposal: Add JSON support

2010-04-06 Thread Tom Lane
Petr Jelinek pjmo...@pjmodos.net writes: Dne 6.4.2010 7:57, Joseph Adams napsal(a): To me, the most logical approach is to do the obvious thing: make JSON's 'null' be SQL's NULL. For instance, SELECTing on a table with NULLs in it and converting the result set to JSON would yield a structure

Re: [HACKERS] Proposal: Add JSON support

2010-04-06 Thread Robert Haas
On Tue, Apr 6, 2010 at 11:05 AM, Alvaro Herrera alvhe...@commandprompt.com wrote: Joseph Adams escribió: 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. Just noticed you don't check the return value

Re: [HACKERS] Proposal: Add JSON support

2010-04-06 Thread Robert Haas
On Tue, Apr 6, 2010 at 12:03 PM, Tom Lane t...@sss.pgh.pa.us wrote: Petr Jelinek pjmo...@pjmodos.net writes: Dne 6.4.2010 7:57, Joseph Adams napsal(a): To me, the most logical approach is to do the obvious thing: make JSON's 'null' be SQL's NULL.  For instance, SELECTing on a table with NULLs

Re: [HACKERS] Proposal: Add JSON support

2010-04-06 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Tue, Apr 6, 2010 at 12:03 PM, Tom Lane t...@sss.pgh.pa.us wrote: To me, what this throws into question is not so much whether JSON null should equate to SQL NULL (it should), but whether it's sane to accept atomic values. With this, I disagree. I

Re: [HACKERS] Proposal: Add JSON support

2010-04-06 Thread Robert Haas
On Tue, Apr 6, 2010 at 1:31 PM, Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: On Tue, Apr 6, 2010 at 12:03 PM, Tom Lane t...@sss.pgh.pa.us wrote: To me, what this throws into question is not so much whether JSON null should equate to SQL NULL (it should), but

Re: [HACKERS] Proposal: Add JSON support

2010-04-06 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Tue, Apr 6, 2010 at 1:31 PM, Tom Lane t...@sss.pgh.pa.us wrote: Oh.  If they're not the same, then the problem is easily dodged, but then what *is* a JSON null? I assume we're going to treat JSON much like XML: basically text, but with some

Re: [HACKERS] Proposal: Add JSON support

2010-04-06 Thread Robert Haas
On Tue, Apr 6, 2010 at 2:20 PM, Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: On Tue, Apr 6, 2010 at 1:31 PM, Tom Lane t...@sss.pgh.pa.us wrote: Oh.  If they're not the same, then the problem is easily dodged, but then what *is* a JSON null? I assume we're

Re: [HACKERS] Proposal: Add JSON support

2010-04-06 Thread Yeb Havinga
Tom Lane wrote: Robert Haas robertmh...@gmail.com writes: With this, I disagree. I see no reason to suppose that a JSON NULL and an SQL NULL are the same thing. Oh. If they're not the same, then the problem is easily dodged, but then what *is* a JSON null? Probably the same as

Re: [HACKERS] Proposal: Add JSON support

2010-04-06 Thread Joseph Adams
On Tue, Apr 6, 2010 at 12:03 PM, Tom Lane t...@sss.pgh.pa.us wrote: Petr Jelinek pjmo...@pjmodos.net writes: Dne 6.4.2010 7:57, Joseph Adams napsal(a): To me, the most logical approach is to do the obvious thing: make JSON's 'null' be SQL's NULL.  For instance, SELECTing on a table with NULLs

Re: [HACKERS] Proposal: Add JSON support

2010-04-06 Thread Tom Lane
Joseph Adams joeyadams3.14...@gmail.com writes: Perhaps there could be conversion functions. E.g.: Yeah, that's what I was thinking about. json_to_string('hello') yields 'hello' json_to_number('3.14159') yields '3.14159' as text (it is up to the user to cast it to the number type

Re: [HACKERS] Proposal: Add JSON support

2010-04-05 Thread Joseph Adams
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

Re: [HACKERS] Proposal: Add JSON support

2010-04-05 Thread Robert Haas
On Mon, Apr 5, 2010 at 11:50 PM, Joseph Adams joeyadams3.14...@gmail.com wrote: In my opinion, we should accept an atomic value as valid JSON content. That seems right to me. Also, should we go even further and accept key:value pairs by themselves? : 'key:value'::JSON Definitely not.

Re: [HACKERS] Proposal: Add JSON support

2010-04-05 Thread Petr Jelinek
Dne 6.4.2010 5:50, Joseph Adams napsal(a): 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

Re: [HACKERS] Proposal: Add JSON support

2010-04-03 Thread Joseph Adams
I've been wondering whether the JSON datatype should be strict or conservative. For one, there's strict JSON (following the exact specification). Then there's more conservative JSON variants. Some JSON parsers support comments, some support invalid number formats (e.g. '3.' or '+5'), etc.. The

Re: [HACKERS] Proposal: Add JSON support

2010-04-03 Thread Mike Rylander
On Sat, Apr 3, 2010 at 8:59 AM, Joseph Adams joeyadams3.14...@gmail.com wrote: I've been wondering whether the JSON datatype should be strict or conservative. For one, there's strict JSON (following the exact specification). Then there's more conservative JSON variants.  Some JSON parsers

Re: [HACKERS] Proposal: Add JSON support

2010-04-03 Thread Andrew Dunstan
Mike Rylander wrote: Here's my idea: the datatype should only allow strict JSON, but there should be a function that accepts a liberal format, cleans it up to make it strict JSON, and converts it to JSON. I think making strict JSON the default makes the most sense because: * Inputs to the

Re: [HACKERS] Proposal: Add JSON support

2010-04-02 Thread David E. Wheeler
On Apr 1, 2010, at 9:34 PM, Petr Jelinek wrote: I ended up reinventing the wheel and writing another JSON library: http://constellationmedia.com/~funsite/static/json-0.0.1.tar.bz2 This is a first release, and it doesn't really have a name besides json. It's very similar to cJSON, except

Re: [HACKERS] Proposal: Add JSON support

2010-04-01 Thread Petr Jelinek
Dne 1.4.2010 5:39, Joseph Adams napsal(a): I ended up reinventing the wheel and writing another JSON library: http://constellationmedia.com/~funsite/static/json-0.0.1.tar.bz2 This is a first release, and it doesn't really have a name besides json. It's very similar to cJSON, except it is

Re: [HACKERS] Proposal: Add JSON support

2010-03-31 Thread Chris Browne
robertmh...@gmail.com (Robert Haas) writes: On Tue, Mar 30, 2010 at 8:58 PM, Josh Berkus j...@agliodbs.com wrote: I'd think that you could get quite a long ways on this, at least doing something like dbslayer without *necessarily* needing to do terribly much work inside the DB engine.

Re: [HACKERS] Proposal: Add JSON support

2010-03-31 Thread Joseph Adams
I ended up reinventing the wheel and writing another JSON library: http://constellationmedia.com/~funsite/static/json-0.0.1.tar.bz2 This is a first release, and it doesn't really have a name besides json. It's very similar to cJSON, except it is (sans unknown bugs) more reliable, more correct,

Re: [HACKERS] Proposal: Add JSON support

2010-03-30 Thread Chris Browne
joeyadams3.14...@gmail.com (Joseph Adams) writes: I introduced myself in the thread Proposal: access control jails (and introduction as aspiring GSoC student), and we discussed jails and session-local variables. But, as Robert Haas suggested, implementing variable support in the backend would

Re: [HACKERS] Proposal: Add JSON support

2010-03-30 Thread Josh Berkus
I'd think that you could get quite a long ways on this, at least doing something like dbslayer without *necessarily* needing to do terribly much work inside the DB engine. There's actually an HTTP framework tool for Postgres which already does something of the sort. It was introduced at

Re: [HACKERS] Proposal: Add JSON support

2010-03-30 Thread Robert Haas
On Tue, Mar 30, 2010 at 8:58 PM, Josh Berkus j...@agliodbs.com wrote: I'd think that you could get quite a long ways on this, at least doing something like dbslayer without *necessarily* needing to do terribly much work inside the DB engine. There's actually an HTTP framework tool for

Re: [HACKERS] Proposal: Add JSON support

2010-03-30 Thread Andrew Dunstan
Robert Haas wrote: While it might be interesting to have/find/write a tool that puts an HTTP/JSON layer around the DB connection, it's pretty much entirely unrelated to the proposed project of creating a json type with PostgreSQL analagous to the xml type we already have, which is what the OP

Re: [HACKERS] Proposal: Add JSON support

2010-03-29 Thread Dimitri Fontaine
Hi, Joseph Adams joeyadams3.14...@gmail.com writes: As for reinventing the wheel, I'm in the process of writing yet another JSON implementation simply because I didn't find the other ones I looked at palatable. Even this one (ANSI C, MIT Licenced)? cJSON -- An ultra-lightweight, portable,

Re: [HACKERS] Proposal: Add JSON support

2010-03-29 Thread Peter Eisentraut
On sön, 2010-03-28 at 23:24 -0400, Joseph Adams wrote: Thus, here's an example of how (in my opinion) character sets and such should be handled in the JSON code: Suppose the client's encoding is UTF-16, and the server's encoding is Latin-1. When JSON is stored to the database: 1. The

Re: [HACKERS] Proposal: Add JSON support

2010-03-29 Thread Andrew Dunstan
Robert Haas wrote: I feel pretty strongly that the data should be stored in the database in the format in which it will be returned to the user - any conversion which is necessary should happen on the way in. I am not 100% sure to what extent we should attempt to canonicalize the input and to

Re: [HACKERS] Proposal: Add JSON support

2010-03-29 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Sun, Mar 28, 2010 at 11:24 PM, Joseph Adams joeyadams3.14...@gmail.com wrote: My reasoning for It should be built-in is:  * It would be nice to have a built-in serialization format that's available by default.  * It might be a little faster

Re: [HACKERS] Proposal: Add JSON support

2010-03-29 Thread Robert Haas
On Mon, Mar 29, 2010 at 12:02 PM, Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: On Sun, Mar 28, 2010 at 11:24 PM, Joseph Adams joeyadams3.14...@gmail.com wrote: My reasoning for It should be built-in is:  * It would be nice to have a built-in serialization

Re: [HACKERS] Proposal: Add JSON support

2010-03-29 Thread Josh Berkus
On 3/28/10 8:52 PM, Hitoshi Harada wrote: There's another choice, called BSON. http://www.mongodb.org/display/DOCS/BSON I've not researched it yet deeply, it seems reasonable to be stored in databases as it is invented for MongoDB. I wouldn't take that for granted. The MongoDB project

Re: [HACKERS] Proposal: Add JSON support

2010-03-29 Thread David E. Wheeler
On Mar 29, 2010, at 9:02 AM, Tom Lane wrote: If this is going to end up being one fairly small C file implementing a spec that is not a moving target, I'd vote against depending on an external library instead, no matter how spiffy and license-compatible the external library might be. Perhaps

Re: [HACKERS] Proposal: Add JSON support

2010-03-29 Thread Joseph Adams
On Mon, Mar 29, 2010 at 2:23 PM, David E. Wheeler da...@kineticode.com wrote: On Mar 29, 2010, at 9:02 AM, Tom Lane wrote: If this is going to end up being one fairly small C file implementing a spec that is not a moving target, I'd vote against depending on an external library instead, no

Re: [HACKERS] Proposal: Add JSON support

2010-03-29 Thread Dimitri Fontaine
Tom Lane t...@sss.pgh.pa.us writes: If this is going to end up being one fairly small C file implementing a spec that is not a moving target, I'd vote against depending on an external library instead, no matter how spiffy and license-compatible the external library might be. My understanding

Re: [HACKERS] Proposal: Add JSON support

2010-03-29 Thread Tom Lane
Dimitri Fontaine dfonta...@hi-media.com writes: Tom Lane t...@sss.pgh.pa.us writes: If this is going to end up being one fairly small C file implementing a spec that is not a moving target, I'd vote against depending on an external library instead, no matter how spiffy and license-compatible

Re: [HACKERS] Proposal: Add JSON support

2010-03-28 Thread Robert Haas
On Sun, Mar 28, 2010 at 4:48 PM, Joseph Adams joeyadams3.14...@gmail.com wrote: I'm wondering whether the internal representation of JSON should be plain JSON text, or some binary code that's easier to traverse and whatnot.  For the sake of code size, just keeping it in text is probably best.

Re: [HACKERS] Proposal: Add JSON support

2010-03-28 Thread Andrew Dunstan
Robert Haas wrote: On Sun, Mar 28, 2010 at 4:48 PM, Joseph Adams joeyadams3.14...@gmail.com wrote: I'm wondering whether the internal representation of JSON should be plain JSON text, or some binary code that's easier to traverse and whatnot. For the sake of code size, just keeping it in

Re: [HACKERS] Proposal: Add JSON support

2010-03-28 Thread Tom Lane
Andrew Dunstan and...@dunslane.net writes: Robert Haas wrote: I think you need to assume that the encoding will be the server encoding, not UTF-8. Although others on this list are better qualified to speak to that than I am. The trouble is that JSON is defined to be specifically Unicode,

Re: [HACKERS] Proposal: Add JSON support

2010-03-28 Thread Andrew Dunstan
Tom Lane wrote: Andrew Dunstan and...@dunslane.net writes: Robert Haas wrote: I think you need to assume that the encoding will be the server encoding, not UTF-8. Although others on this list are better qualified to speak to that than I am. The trouble is that JSON is

Re: [HACKERS] Proposal: Add JSON support

2010-03-28 Thread Tom Lane
Andrew Dunstan and...@dunslane.net writes: Here's another thought. Given that JSON is actually specified to consist of a string of Unicode characters, what will we deliver to the client where the client encoding is, say Latin1? Will it actually be a legal JSON byte stream? No, it won't.

Re: [HACKERS] Proposal: Add JSON support

2010-03-28 Thread Robert Haas
On Sun, Mar 28, 2010 at 7:36 PM, Tom Lane t...@sss.pgh.pa.us wrote: Andrew Dunstan and...@dunslane.net writes: Here's another thought. Given that JSON is actually specified to consist of a string of Unicode characters, what will we deliver to the client where the client encoding is, say

Re: [HACKERS] Proposal: Add JSON support

2010-03-28 Thread Mike Rylander
On Sun, Mar 28, 2010 at 7:36 PM, Tom Lane t...@sss.pgh.pa.us wrote: Andrew Dunstan and...@dunslane.net writes: Here's another thought. Given that JSON is actually specified to consist of a string of Unicode characters, what will we deliver to the client where the client encoding is, say

Re: [HACKERS] Proposal: Add JSON support

2010-03-28 Thread Robert Haas
On Sun, Mar 28, 2010 at 8:23 PM, Mike Rylander mrylan...@gmail.com wrote: In practice, every parser/serializer I've used (including the one I helped write) allows (and, often, forces) any non-ASCII character to be encoded as \u followed by a string of four hex digits. Is it correct to say that

Re: [HACKERS] Proposal: Add JSON support

2010-03-28 Thread Andrew Dunstan
Robert Haas wrote: On Sun, Mar 28, 2010 at 8:23 PM, Mike Rylander mrylan...@gmail.com wrote: In practice, every parser/serializer I've used (including the one I helped write) allows (and, often, forces) any non-ASCII character to be encoded as \u followed by a string of four hex digits.

Re: [HACKERS] Proposal: Add JSON support

2010-03-28 Thread Andrew Dunstan
Andrew Dunstan wrote: Robert Haas wrote: On Sun, Mar 28, 2010 at 8:23 PM, Mike Rylander mrylan...@gmail.com wrote: In practice, every parser/serializer I've used (including the one I helped write) allows (and, often, forces) any non-ASCII character to be encoded as \u followed by a

Re: [HACKERS] Proposal: Add JSON support

2010-03-28 Thread Mike Rylander
On Sun, Mar 28, 2010 at 8:33 PM, Robert Haas robertmh...@gmail.com wrote: On Sun, Mar 28, 2010 at 8:23 PM, Mike Rylander mrylan...@gmail.com wrote: In practice, every parser/serializer I've used (including the one I helped write) allows (and, often, forces) any non-ASCII character to be

Re: [HACKERS] Proposal: Add JSON support

2010-03-28 Thread Joseph Adams
On Sun, Mar 28, 2010 at 5:19 PM, Robert Haas robertmh...@gmail.com wrote: On Sun, Mar 28, 2010 at 4:48 PM, Joseph Adams joeyadams3.14...@gmail.com wrote: Now my thoughts and opinions on the JSON parsing/unparsing itself: It should be built-in, rather than relying on an external library (like

Re: [HACKERS] Proposal: Add JSON support

2010-03-28 Thread Robert Haas
On Sun, Mar 28, 2010 at 11:24 PM, Joseph Adams joeyadams3.14...@gmail.com wrote: I apologize; I was just starting the conversation with some of my ideas to receive feedback.  I didn't want people to have to wade through too many I thinks .  I'll be sure to use opinion tags in the future :-)

Re: [HACKERS] Proposal: Add JSON support

2010-03-28 Thread Hitoshi Harada
2010/3/29 Andrew Dunstan and...@dunslane.net: Robert Haas wrote: On Sun, Mar 28, 2010 at 4:48 PM, Joseph Adams joeyadams3.14...@gmail.com wrote: I'm wondering whether the internal representation of JSON should be plain JSON text, or some binary code that's easier to traverse and whatnot.