PostgreSQL json_strip_nulls() Function

The PostgreSQL json_strip_nulls() function removes fields with null values ​​in the specified JSON object recursively, and null values ​​in non-object fields are not processed.

json_strip_nulls() Syntax

This is the syntax of the PostgreSQL json_strip_nulls() function:

json_strip_nulls(json_value JSON) -> JSON



Required. The JSON value to process.

Return value

The PostgreSQL json_strip_nulls() function returns the given JSON value with null fields are removed recursively.

If you provide a NULL parameter, the json_strip_nulls() function will return NULL.

json_strip_nulls() Examples

The following example shows how to use the PostgreSQL json_strip_nulls() function to remove a null object field from a given JSON value.

SELECT json_strip_nulls('[1, null, 3, {"x": 1, "y": null}]');

Here, only the field y in the JOSN object {"x": 1, "y": null} are removed, and the null values ​​in the array are not removed.