Re: JSON for PG 9.2 - Mailing list pgsql-hackers

From Peter van Hardenberg
Subject Re: JSON for PG 9.2
Date
Msg-id CAAcg=kUJDjx4QQoUt3Ebgj-mSYp_uGj90aR7x=fQ8ez2DO-o8Q@mail.gmail.com
Whole thread Raw
In response to Re: JSON for PG 9.2  (Josh Berkus <josh@agliodbs.com>)
Responses Re: JSON for PG 9.2  ("David E. Wheeler" <david@justatheory.com>)
Re: JSON for PG 9.2  (Andrew Dunstan <andrew@dunslane.net>)
Re: JSON for PG 9.2  (Daniel Farina <daniel@heroku.com>)
Re: JSON for PG 9.2  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-hackers
We reached out to Joseph to see if we could help sponsor the project,
but never really heard back from him.

Because we haven't heard from him in a while we've been using PL/V8 to
validate a JSON datatype simulated by a DOMAIN with a simple
acceptance function. (See below.) This is not ideally performant but
thanks to V8's JIT the JSON parser is actually reasonably good.

I think releasing something simple and non-performant with reasonable
semantics would be the best next step. If it were up to me, I'd
probably even try to just land PL/V8 as PL/JavaScript for 9.2 if the
crash bugs and deal breakers can be sifted out.

PL/V8 is fast, it's sandboxed, and while it doesn't provide GIN or
GIST operators out of the box, maybe those could be motivated by its
inclusion.

Andrew, you've been down in the guts here, what do you think?

-pvh

(Code sample.)

create or replace function valid_json(json text)
returns bool as $$ try { JSON.parse(json); return true } catch(e) { return false}
$$ LANGUAGE plv8 IMMUTABLE STRICT;

select valid_json('{"key": "value"}'), valid_json('lol');
valid_json | t
valid_json | f
Time: 0.283 ms

create domain json as text check(valid_json(VALUE));
create table jsononly(data json);

insert into jsononly values 'lol';
ERROR:  syntax error at or near "'lol'"
LINE 1: insert into jsononly values 'lol';

insert into jsononly values ('{"ok": true}');
INSERT 0 1

-p

On Mon, Dec 12, 2011 at 1:34 PM, Josh Berkus <josh@agliodbs.com> wrote:
> Bruce,
>
> I thought that Joseph Adams was still working on this, sponsored by
> Heroku.  Joseph?
>
>
> --
> Josh Berkus
> PostgreSQL Experts Inc.
> http://pgexperts.com
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers



--
Peter van Hardenberg
San Francisco, California
"Everything was beautiful, and nothing hurt." -- Kurt Vonnegut


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Is anybody actually using XLR_BKP_REMOVABLE?
Next
From: "David E. Wheeler"
Date:
Subject: Re: WIP: URI connection string support for libpq