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

Поиск
Список
Период
Сортировка
От Ryan Pedela
Тема Re: Add jsonb_compact(...) for whitespace-free jsonb to text
Дата
Msg-id CACu89FRDhDYTsU8Ei6hDWdVw-SQ2Mu6kTytQ+Kiy5KmTw97djw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Add jsonb_compact(...) for whitespace-free jsonb to text  (Stephen Frost <sfrost@snowman.net>)
Ответы Re: Add jsonb_compact(...) for whitespace-free jsonb to text  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-hackers
On Tue, Apr 26, 2016 at 10:49 AM, Stephen Frost <sfrost@snowman.net> wrote:
* Ryan Pedela (rpedela@datalanche.com) wrote:
> On Sun, Apr 24, 2016 at 4:02 PM, Sehrope Sarkuni <sehrope@jackdb.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.

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Andres Freund
Дата:
Сообщение: Re: [BUGS] Breakage with VACUUM ANALYSE + partitions
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Add jsonb_compact(...) for whitespace-free jsonb to text