From 4603903d294bbdd644afecf9b5970827db6d1ff5 Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Wed, 5 Mar 2025 09:50:34 -0500 Subject: Allow json{b}_strip_nulls to remove null array elements An additional paramater ("strip_in_arrays") is added to these functions. It defaults to false. If true, then null array elements are removed as well as null valued object fields. JSON that just consists of a single null is not affected. Author: Florents Tselai Discussion: https://postgr.es/m/4BCECCD5-4F40-4313-9E98-9E16BEB0B01D@gmail.com --- doc/src/sgml/func.sgml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index bf31b1f3eee..f97f0ce570a 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -17345,25 +17345,32 @@ ERROR: value too long for type character(2) json_strip_nulls - json_strip_nulls ( json ) + json_strip_nulls ( target jsonb, ,strip_in_arrays boolean ) json jsonb_strip_nulls - jsonb_strip_nulls ( jsonb ) + jsonb_strip_nulls ( target jsonb, ,strip_in_arrays boolean ) jsonb Deletes all object fields that have null values from the given JSON - value, recursively. Null values that are not object fields are - untouched. + value, recursively. + If strip_in_arrays is true (the default is false), + null array elements are also stripped. + Otherwise they are not stripped. Bare null values are never stripped. json_strip_nulls('[{"f1":1, "f2":null}, 2, null, 3]') [{"f1":1},2,null,3] - + + + jsonb_strip_nulls('[1,2,null,3,4]', true); + [1,2,3,4] + + -- cgit v1.2.3