[prev in list] [next in list] [prev in thread] [next in thread]
List: postgresql-general
Subject: Re: [HACKERS] Add jsonb_compact(...) for whitespace-free jsonb to text
From: Merlin Moncure <mmoncure () gmail ! com>
Date: 2016-04-29 22:11:07
Message-ID: CAHyXU0wMh6CRY8eYcAqVMdO7mJks65yuAE0rhiE7=bVBBY83ZQ () mail ! gmail ! com
[Download RAW message or body]
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
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic