Re: mogrify and indent features for jsonb

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Sehrope Sarkuni <sehrope(at)jackdb(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: mogrify and indent features for jsonb
Date: 2015-02-15 17:10:47
Message-ID: 54E0D317.3080201@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 02/15/2015 11:47 AM, Sehrope Sarkuni wrote:
> For jsonb_indent, how about having it match up closer to the
> JavaScript JSON.stringify(value, replacer, space)[1]? That way a user
> can specify the indentation level and optionally filter the fields
> they'd like to output.
>
> In JS, the "replacer" parameter can be either a JS function or an
> array of property names. I don't think the former is really possible
> (in a SQL callable function) but the latter would be a text[]. The
> "space" parameter can be either a string (used directly) or a number
> (corresponding number of spaces).
>
> The PG function signatures would be something like:
>
> CREATE OR REPLACE FUNCTION jsonb_stringify(obj jsonb, replacer text[],
> space text)
> CREATE OR REPLACE FUNCTION jsonb_stringify(obj jsonb, replacer text[],
> space int)
>
> For convenience we could also include overloads with replacer removed
> (since most people probably want the entire object):
>
> CREATE OR REPLACE FUNCTION jsonb_stringify(obj jsonb, space text)
> CREATE OR REPLACE FUNCTION jsonb_stringify(obj jsonb, space int)
>
> Having json_stringify versions of these would be useful as well.
>

I think if you want these things, especially the filtering, you should
probably load PLV8.

We could probably do the rest, but I'm not sure it's worth doing given
that PLV8 is available for all of it.

cheers

andrew

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-02-15 17:11:52 Re: NOT NULL markings for BKI columns
Previous Message Peter Eisentraut 2015-02-15 17:02:44 Re: pgsql: pg_upgrade: quote directory names in delete_old_cluster script