Re: Add jsonb_compact(...) for whitespace-free jsonb to text
| От | Merlin Moncure |
|---|---|
| Тема | Re: Add jsonb_compact(...) for whitespace-free jsonb to text |
| Дата | |
| Msg-id | CAHyXU0wMh6CRY8eYcAqVMdO7mJks65yuAE0rhiE7=bVBBY83ZQ@mail.gmail.com обсуждение исходный текст |
| Ответ на | Re: Add jsonb_compact(...) for whitespace-free jsonb to text (Andrew Dunstan <andrew@dunslane.net>) |
| Ответы |
Re: Add jsonb_compact(...) for whitespace-free jsonb to
text
|
| Список | pgsql-hackers |
On Fri, Apr 29, 2016 at 4:06 PM, Andrew Dunstan <andrew@dunslane.net> wrote:
> One other point: I think we really need most of these pieces - if we are
> going to squash the whitespace we need functions to do that cleanly for json
> and to pretty-print json.
I don't think it should be squashed per se -- we just don't *add* any
whitespace. So the current behavior of to_json,
postgres=# select to_json(q) from (select 1, '{"a" : "foo"}'::json) q; to_json
───────────────────────────────────────{"?column?":1,"json":{"a" : "foo"}}
...is correct to me on the premise that the user deliberately chose
the whitespace preserving json type and did not run compat on it.
However,
postgres=# select row_to_json(q) from (select 1, '{"a" : "foo"}'::jsonb) q; row_to_json
─────────────────────────────────────{"?column?":1,"jsonb":{"a": "foo"}}
really ought to render (note lack of space after "a"):{"?column?":1,"jsonb":{"a":"foo"}}
This is a simple matter of removing spaces in the occasional C string
literal in the serialization routines and adding a json_pretty
function.
merlin
В списке pgsql-hackers по дате отправления: