Re: json_strip_nulls()

From: Erwin Brandstetter <brsaweda(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, pgsql-docs <pgsql-docs(at)postgresql(dot)org>
Subject: Re: json_strip_nulls()
Date: 2022-01-23 07:44:28
Message-ID: CAGHENJ6i2_M0KWvN_=SfRCtzpfFFQxpeBjSPjcO6X9qV=rXt6w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Sat, 22 Jan 2022 at 22:00, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Erwin Brandstetter <brsaweda(at)gmail(dot)com> writes:
> > On Sat, 22 Jan 2022 at 20:31, David G. Johnston <
> david(dot)g(dot)johnston(at)gmail(dot)com>
> > wrote:
> >> json_strip_nulls doesn't make any promise regarding its output json
> other
> >> than that it is valid. Since we are munging the json we are arguably
> >> within our rights to output whatever transformed version we want. The
> >> format should not be documented.
>
> > Within our rights, maybe. The manual makes related promises[1]:
> >> Because the json type stores an exact copy of the input text, it will
> >> preserve semantically-insignificant white space between tokens
> > And[2]:
> >> As previously stated, when a JSON value is input and then printed
> without
> >> any additional processing, json outputs the same text that was input,
>
> "Without any additional processing" is the key restriction there.
>
> > Not strictly contradicting, but the current behavior of
> json_strip_nulls()
> > is still surprising. Either the input should be preserved as far as
> > possible or, failing that, the actual behavior documented.
>
> It is documented --- you just quoted the text that does so.
>
> I don't have a lot of sympathy for "JSON-reading" code that fails to
> conform to the JSON RFC, so I'm disinclined to work harder than that.
>
>
I suggest to clarify the behavior of json_strip_nulls() in the manual: that
it also strips insignificant white space. If that may change in future
versions, also say so. People are starting to use json_strip_nulls() for
the purpose (and may regret it later):
https://stackoverflow.com/questions/27505181/fetching-compact-version-of-jsonb-in-postgresql/56842519#56842519

If (like I assume) json_strip_nulls() should not be relied upon to strip
whitespace, it would be great to have a separate, dedicated function for
that. That's independent from the first suggestion.

Regards
Erwin

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Eric Mutta 2022-01-24 20:48:05 Re: Typo in "27.2.8. Synchronous Replication"
Previous Message Tom Lane 2022-01-22 21:00:39 Re: json_strip_nulls()