Re: Add jsonb_compact(...) for whitespace-free jsonb to text - Mailing list pgsql-hackers

From Merlin Moncure
Subject Re: Add jsonb_compact(...) for whitespace-free jsonb to text
Date
Msg-id CAHyXU0wMh6CRY8eYcAqVMdO7mJks65yuAE0rhiE7=bVBBY83ZQ@mail.gmail.com
Whole thread Raw
In response to Re: Add jsonb_compact(...) for whitespace-free jsonb to text  (Andrew Dunstan <andrew@dunslane.net>)
Responses Re: Add jsonb_compact(...) for whitespace-free jsonb to text  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-hackers
On Fri, Apr 29, 2016 at 4:06 PM, Andrew Dunstan <andrew@dunslane.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



pgsql-hackers by date:

Previous
From: Kevin Grittner
Date:
Subject: Re: Re: [COMMITTERS] pgsql: Avoid extra locks in GetSnapshotData if old_snapshot_threshold <
Next
From: Michael Paquier
Date:
Subject: Re: VS 2015 support in src/tools/msvc