json rendering without pretty option (compact)

Started by Nicolas Parisover 9 years ago3 messagesgeneral
Jump to latest
#1Nicolas Paris
niparisco@gmail.com

Hello,

I want to minimize postgresql json size when I fetch them.
I translate columnar table to json thought json_build_object/array or even
row_to_jeon.

While row_to_json do have a "pretty_bool" option, the latter do not. Each
json object/array I build contains spaces.

Is there a workaround ?
Is there a plan to add this feature on future version ?

(PG 9.6)

Thank you by advance,

#2Michael Paquier
michael@paquier.xyz
In reply to: Nicolas Paris (#1)
Re: json rendering without pretty option (compact)

On Wed, Oct 19, 2016 at 2:00 AM, Nicolas Paris <niparisco@gmail.com> wrote:

I want to minimize postgresql json size when I fetch them.
I translate columnar table to json thought json_build_object/array or even
row_to_jeon.

While row_to_json do have a "pretty_bool" option, the latter do not. Each
json object/array I build contains spaces.

Is there a workaround ?

Not any direct way that I know of :( If you have a lot of spaces in a
JSON blob between each object, it may be worth casting it once to
jsonb. This takes an extra round of conversion overhead though.

Is there a plan to add this feature on future version ?

I don't recall plans in this area. Maybe there's room for a
jsonb_compact(). core has already jsonb_pretty(), and that would be
what has the less overhead when doing the binary/text conversion.
--
Michael

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Merlin Moncure
mmoncure@gmail.com
In reply to: Nicolas Paris (#1)
Re: json rendering without pretty option (compact)

On Tue, Oct 18, 2016 at 12:00 PM, Nicolas Paris <niparisco@gmail.com> wrote:

Hello,

I want to minimize postgresql json size when I fetch them.
I translate columnar table to json thought json_build_object/array or even
row_to_jeon.

While row_to_json do have a "pretty_bool" option, the latter do not. Each
json object/array I build contains spaces.

Is there a workaround ?
Is there a plan to add this feature on future version ?

There is gradual movement towards having all the generation functions
being completely compact. Personally I view the pretty flag as being
a legacy setting formatting should be handled by a separate routine,
which would be more expensive but much more flexible.

merlin

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general