From 237a8824430c607fce1eafde0c625744d50a455c Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Fri, 12 Dec 2014 09:00:43 -0500 Subject: Add json_strip_nulls and jsonb_strip_nulls functions. The functions remove object fields, including in nested objects, that have null as a value. In certain cases this can lead to considerably smaller datums, with no loss of semantic information. Andrew Dunstan, reviewed by Pavel Stehule. --- doc/src/sgml/func.sgml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'doc/src') diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index c3b61269438..da138e1fee7 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -10716,6 +10716,19 @@ table2-mapping + + json_strip_nulls(from_json json) + jsonb_strip_nulls(from_json jsonb) + + jsonjsonb + + Returns from_json + with all object fields that have null values omitted. Other null values + are untouched. + + json_strip_nulls('[{"f1":1,"f2":null},2,null,3]') + [{"f1":1},2,null,3] + @@ -10752,6 +10765,16 @@ table2-mapping + + + If the argument to json_strip_nulls contains duplicate + field names in any object, the result could be semantically somewhat + different, depending on the order in which they occur. This is not an + issue for jsonb_strip_nulls since jsonb values never have + duplicate object field names. + + + See also for the aggregate function json_agg which aggregates record -- cgit v1.2.3