Re: json_strip_nulls()

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Erwin Brandstetter <brsaweda(at)gmail(dot)com>
Cc: pgsql-docs <pgsql-docs(at)postgresql(dot)org>
Subject: Re: json_strip_nulls()
Date: 2022-01-22 19:31:10
Message-ID: CAKFQuwYeVypxm+oY9WvnxeJLgyZWCfNdf6_M-3EKjbSgMoPmXQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Sat, Jan 22, 2022 at 12:11 PM Erwin Brandstetter <brsaweda(at)gmail(dot)com>
wrote:

> But the function also strips all insignificant white space:
>
> test=> SELECT json_strip_nulls(json '{"a": 1 ,
> test'> "foo" : "bar"
> test'> }');
> json_strip_nulls
> ---------------------
> {"a":1,"foo":"bar"}
>
> This is a useful feature to trim noise from json values, but unreliable
> while undocumented. So let's document the behavior:
>

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.

>
> If that's undesirable, let's remove the functionality - and provide a
> dedicated function for the task.
>

I agree we should at least provide a function that takes a json or jsonb
and outputs its text representation in a minimalist form.

I found similar (unresolved) considerations here:
>
> https://www.postgresql.org/message-id/20160610110633.GG18838%40zip.com.au
>
>
This whole situation went through a fairly lengthy discussion back in 2016:

https://www.postgresql.org/message-id/flat/CAH7T-ap6R_xzWz98c6AQzQuGsK_vpgr-et4VRaSjgxqom--ibw%40mail.gmail.com

It's an interesting, and IMO, disappointing thread. Maybe we can do better
now and focus on one missing capability the community desires and actually
get something committed.

David J.

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Erwin Brandstetter 2022-01-22 20:20:21 Re: json_strip_nulls()
Previous Message Erwin Brandstetter 2022-01-22 19:10:46 json_strip_nulls()