STRIP_NULL_VALUE
Description
The STRIP_NULL_VALUE function converts NULL values in JSON to NULL values in SQL. All other variant values remain unchanged.
Syntax
STRIP_NULL_VALUE( <json_doc> )
Required Parameters
<json_doc>: JSON type, the JSON object to be processed.
Usage Notes
- If the argument is NULL, returns NULL.
- If the argument is json null, returns NULL.
- For json data that is not null, returns the original input.
Examples
- Prepare data
create table my_test(id INT, v json) properties('replication_num' = '1');
insert into my_test values(0, 'null'), (1, null), (2, 123), (3, '{"key": 445}'), (4, '{"key": null}');
select * from my_test;
-
Example 1
select id, v, strip_null_value(v) from my_test order by id;+------+--------------+---------------------+| id | v | strip_null_value(v) |+------+--------------+---------------------+| 0 | null | NULL || 1 | NULL | NULL || 2 | 123 | 123 || 3 | {"key":445} | {"key":445} || 4 | {"key":null} | {"key":null} |+------+--------------+---------------------+5 rows in set (0.02 sec) -
Example 2
selectid, v, strip_null_value(json_extract(v, '$.key'))from my_test order by id;+------+--------------+--------------------------------------------+| id | v | strip_null_value(json_extract(v, '$.key')) |+------+--------------+--------------------------------------------+| 0 | null | NULL || 1 | NULL | NULL || 2 | 123 | NULL || 3 | {"key":445} | 445 || 4 | {"key":null} | NULL |+------+--------------+--------------------------------------------+