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

From: Ryan Pedela <rpedela(at)datalanche(dot)com>
To: Sehrope Sarkuni <sehrope(at)jackdb(dot)com>
Cc: "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-26 16:34:06
Message-ID: CACu89FR43b9C3e-p=zAJ73UD_urhSLOiuYugn-aAK4Wy92=xCA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Apr 24, 2016 at 4:02 PM, Sehrope Sarkuni <sehrope(at)jackdb(dot)com> wrote:

> Hi,
>
> The default text representation of jsonb adds whitespace in between
> key/value pairs (after the colon ":") and after successive properties
> (after the comma ","):
>
> postgres=# SELECT '{"b":2,"a":1}'::jsonb::text;
> text
> ------------------
> {"a": 1, "b": 2}
> (1 row)
>
> AFAIK, there's also no guarantee on the specific order of the resulting
> properties in the text representation either. I would suppose it's fixed
> for a given jsonb value within a database major version but across major
> versions it could change (if the underlying representation changes).
>
> I originally ran into this when comparing the hashes of the text
> representation of jsonb columns. The results didn't match up because the
> javascript function JSON.stringify(...) does not add any extra whitespace.
>
> It'd be nice to have a stable text representation of a jsonb value with
> minimal whitespace. The latter would also save a few bytes per record in
> text output formats, on the wire, and in backups (ex: COPY ... TO STDOUT).
>

+1

I cannot comment on the patch itself, but I welcome jsonb_compact() or some
way to get JSON with no inserted whitespace.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2016-04-26 16:49:10 Re: Add jsonb_compact(...) for whitespace-free jsonb to text
Previous Message Peter Eisentraut 2016-04-26 16:02:36 Re: [COMMITTERS] pgsql: Add trigonometric functions that work in degrees.