From: | "Shulgin, Oleksandr" <oleksandr(dot)shulgin(at)zalando(dot)de> |
---|---|
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 13:56:20 |
Message-ID: | CACACo5RuOhqVzMuv8HTDRHxHruHk8JkYo7_cf3ZtYsrgz3SQJg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, Apr 29, 2016 at 3:18 PM, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
>
> On 04/28/2016 04:29 PM, Alvaro Herrera wrote:
>
>>
>>> Actually we did have someone come up with a patch to "normalize" how
>> JSON stuff was output, because our code seems to do it in three
>> different, inconsistent ways. And our response was for them to get the
>> heck outta here, because we're so much in love with our current
>> practice that we don't need to refactor the three implementations into a
>> single one.
>>
>
> That's a pretty bad mischaracterization of the discussion. What was
> proposed was broken, as I pointed out to the OP, and then again later to
> you when you asked about it. What he wanted to achieve simply couldn't be
> done they way he was trying to achieve it.
>
Yeah, the original request was pretty invalid, but when I've proposed to
resubmit just the normalization of whitespace nobody has shown enthusiasm
about the idea either:
Regarding the present proposal:
>
> I wouldn't necessarily be opposed to us having one or more of the
> following:
>
> a) suppressing whitespace addition in all json generation and text output,
> possibly governed by a GUC setting so we could maintain behaviour
> compatibility if required
>
I'm not thrilled about GUC that would silently break stuff. That being
said, if someone's code is dependent on exact placement of whitespace in
the JSON text, it's pretty broken already and it's just a matter of time
when they hit an issue there.
> b) a function to remove whitespace from json values, but otherwise
> preserve things like key order
> c) a function to pretty-print json similar to the output from jsonb, but
> again preserving key order
> d) a function to reorder keys in json so they were sorted according to the
> relevant collation.
>
> None of these things except possibly the last should be terribly difficult
> to do.
>
My vote goes to remove all optional whitespace by default and have a single
function to prettify it. Key reordering can then be handled with an
optional parameter to such prettifying function.
It would probably make sense model this function after Python's
"dump-to-JSON-string" function:
https://docs.python.org/2/library/json.html#json.dumps With the optional
parameters for sorting the keys, indentation size and punctuation. This
way all the prettiness enhancements could be contained in a single function
w/o the need for generalized interface used in many places.
How about that?
--
Alex
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2016-04-29 14:02:38 | Re: VS 2015 support in src/tools/msvc |
Previous Message | Tom Lane | 2016-04-29 13:49:07 | Re: 9.6 and fsync=off |