Confession: I am a Google Summer of Code 2010 student who tried to bring JSON support for PostgreSQL 9.1. Although my code was pretty full-featured, it wasn’t completely upstream ready, and the PostgreSQL developer community was considering some alternative implementations. However, with the spring transition, I hope to finish my rewrite and give it one last push this week.
At the same time, you can download and install the incomplete JSON module of the data type , which should work on PostgreSQL 8.4. 0 and above. This is the PGXS module, so you can compile and install it without compiling the entire PostgreSQL. However, you will need the PostgreSQL server development headers.
Installation takes place like this:
git clone git://git.postgresql.org/git/json-datatype.git cd json-datatype/ USE_PGXS=1 make sudo USE_PGXS=1 make install psql -f json.sql <DBNAME1>
Although you only need to complete the assembly and installation once, json.sql needs to be run in every database on which you intend to use the JSON data type.
With the program installed, you can run:
=> SELECT to_json(E'"quotes and \n newlines"\n'::TEXT); to_json -------------------------------- "\"quotes and \n newlines\"\n" (1 row)
Note that this does not escape characters other than ASCII.
source share