json_strip_nulls() - Mailing list pgsql-docs

From Erwin Brandstetter
Subject json_strip_nulls()
Date
Msg-id CAGHENJ5OckBWa22Cf=N9e68EZM2=_S8AWjWF-_xnGa+iktUh7g@mail.gmail.com
Whole thread Raw
Responses Re: json_strip_nulls()  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-docs
The manual says this about json_strip_nulls()[1]:

> Deletes all object fields that have null values from the given JSON value, recursively. Null values that are not object fields are untouched.


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:

Deletes all object fields that have null values from the given JSON value, recursively. Null values that are not object fields are untouched. json_strip_nulls additionally removes all insignificant white space.

If that's undesirable, let's remove the functionality - and provide a dedicated function for the task.
I found similar (unresolved) considerations here:

pgsql-docs by date:

Previous
From: PG Doc comments form
Date:
Subject: array_to_string and string_to_array
Next
From: "David G. Johnston"
Date:
Subject: Re: json_strip_nulls()