From: | Oleksandr Shulgin <oleksandr(dot)shulgin(at)zalando(dot)de> |
---|---|
To: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
Cc: | Merlin Moncure <mmoncure(at)gmail(dot)com>, 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-05-02 16:22:40 |
Message-ID: | CACACo5Rkf3n3LnvB74FUB4nDNdUaGWeQG+e3=Go6gg2FjM9EiA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Mon, May 2, 2016 at 4:04 PM, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
>
> On 05/02/2016 04:56 AM, Shulgin, Oleksandr wrote:
>
>> On Sun, May 1, 2016 at 3:22 AM, Andrew Dunstan <andrew(at)dunslane(dot)net
>> <mailto:andrew(at)dunslane(dot)net>> wrote:
>>
>> On 04/29/2016 06:11 PM, Merlin Moncure wrote:
>>
>> This is a simple matter of removing spaces in the occasional C
>> string
>> literal in the serialization routines and adding a json_pretty
>> function.
>>
>>
>> I spent a few hours on this. See
>> <https://bitbucket.org/adunstan/pgdevel/commits/branch/jsonformat>
>> for WIP - there are three commits. No regression tests yet for the
>> two new functions (json_squash and json_pretty), Otherwise fairly
>> complete. Removing whitespace generation was pretty simple for
>> both json and jsonb.
>>
>>
>> Looks good, thank you!
>>
>> It would make sense IMO to rename FormatState's `indent' field as
>> `pretty': it's being used to add whitespace between the punctuation, not
>> only at start of a line. I'd also move the "if (indent)" check out of
>> add_indent(): just don't call it if no indent is needed.
>>
>> I'll try to play with the patch to produce some regression tests for the
>> new functions.
>>
>>
> It was done the way it was to be as consistent as possible with how it's
> done for jsonb (c.f. jsonb.c:JsonbToCStringWorker and jsonb.c::add_indent).
>
Ah, I see.
Simply taking regression tests for jsonb_pretty() and using them against
json_pretty() revealed a bug with extra indent being added before every
array/object start. Attached patch fixes that and adds the regression
tests.
For json_squash() I've taken the same three test values, for lack of a
better idea at the moment. At least we are testing key order stability and
that no whitespace is spit out.
Regards,
--
Alex
Attachment | Content-Type | Size |
---|---|---|
json-format-add-regression-tests.diff | text/plain | 5.0 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2016-05-02 16:25:44 | Re: [sqlsmith] Failed assertion in BecomeLockGroupLeader |
Previous Message | Robert Haas | 2016-05-02 16:21:07 | Re: 9.6 and fsync=off |