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

From: Ryan Pedela <rpedela(at)datalanche(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: 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-28 17:00:33
Message-ID: CACu89FRDhDYTsU8Ei6hDWdVw-SQ2Mu6kTytQ+Kiy5KmTw97djw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Apr 26, 2016 at 10:49 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:

> * Ryan Pedela (rpedela(at)datalanche(dot)com) wrote:
> > On Sun, Apr 24, 2016 at 4:02 PM, Sehrope Sarkuni <sehrope(at)jackdb(dot)com>
> wrote:
> > > The default text representation of jsonb adds whitespace in between
> > > key/value pairs (after the colon ":") and after successive properties
> > > (after the comma ","):
>
> [...]
>
> > > 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.
>
> As I mentioned to Sehrope on IRC, at least for my 2c, if you want a
> compact JSON format to reduce the amount of traffic over the wire or to
> do things with on the client side, we should probably come up with a
> binary format, rather than just hack out the whitespace. It's not like
> representing numbers using ASCII characters is terribly efficient
> either.

Why build a Ferrari when a skateboard would suffice? Besides, that doesn't
help one of the most common cases for JSONB: REST APIs.

Now that PG fully supports JSON, a user can use PG to construct the JSON
payload of a REST API request. Then the web server would simply be a
pass-through for the JSON payload. I personally have this use case, it is
not hypothetical. However currently, a user must parse the JSON string from
PG and re-stringify it to minimize the whitespace. Given that HTTP is
text-based, removing all extraneous whitespace is the best way to compress
it, and on top of that you can do gzip compression. Unless you are
suggesting that the binary format is just a gzipped version of the
minimized text format, I don't see how a binary format helps at all in the
REST API case.

In addition, every JSON implementation I have ever seen fully minimizes
JSON by default. PG appears to deviate from standard practice for no
apparent reason.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David G. Johnston 2016-04-28 17:30:21 Re: Add jsonb_compact(...) for whitespace-free jsonb to text
Previous Message Andres Freund 2016-04-28 16:49:47 Re: [BUGS] Breakage with VACUUM ANALYSE + partitions