Re: Add jsonb_compact(...) for whitespace-free jsonb to text

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Ryan Pedela <rpedela(at)datalanche(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, Sehrope Sarkuni <sehrope(at)jackdb(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add jsonb_compact(...) for whitespace-free jsonb to text
Date: 2016-04-29 22:11:07
Message-ID: CAHyXU0wMh6CRY8eYcAqVMdO7mJks65yuAE0rhiE7=bVBBY83ZQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Apr 29, 2016 at 4:06 PM, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
> One other point: I think we really need most of these pieces - if we are
> going to squash the whitespace we need functions to do that cleanly for json
> and to pretty-print json.

I don't think it should be squashed per se -- we just don't *add* any
whitespace. So the current behavior of to_json,

postgres=# select to_json(q) from (select 1, '{"a" : "foo"}'::json) q;
to_json
───────────────────────────────────────
{"?column?":1,"json":{"a" : "foo"}}

...is correct to me on the premise that the user deliberately chose
the whitespace preserving json type and did not run compat on it.
However,
postgres=# select row_to_json(q) from (select 1, '{"a" : "foo"}'::jsonb) q;
row_to_json
─────────────────────────────────────
{"?column?":1,"jsonb":{"a": "foo"}}

really ought to render (note lack of space after "a"):
{"?column?":1,"jsonb":{"a":"foo"}}

This is a simple matter of removing spaces in the occasional C string
literal in the serialization routines and adding a json_pretty
function.

merlin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2016-04-29 22:22:11 Re: VS 2015 support in src/tools/msvc
Previous Message Kevin Grittner 2016-04-29 22:08:49 Re: Re: [COMMITTERS] pgsql: Avoid extra locks in GetSnapshotData if old_snapshot_threshold <