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

Поиск
Список
Период
Сортировка
От Ryan Pedela
Тема Re: Add jsonb_compact(...) for whitespace-free jsonb to text
Дата
Msg-id CACu89FR43b9C3e-p=zAJ73UD_urhSLOiuYugn-aAK4Wy92=xCA@mail.gmail.com
обсуждение исходный текст
Ответ на Add jsonb_compact(...) for whitespace-free jsonb to text  (Sehrope Sarkuni <sehrope@jackdb.com>)
Ответы Re: Add jsonb_compact(...) for whitespace-free jsonb to text  (Stephen Frost <sfrost@snowman.net>)
Список pgsql-hackers
On Sun, Apr 24, 2016 at 4:02 PM, Sehrope Sarkuni <sehrope@jackdb.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.

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

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: [COMMITTERS] pgsql: Add trigonometric functions that work in degrees.
Следующее
От: Stephen Frost
Дата:
Сообщение: Re: Add jsonb_compact(...) for whitespace-free jsonb to text