The explode_json_object table function expands a JSON object into multiple rows, each containing a key-value pair. It is commonly used to transform JSON objects into a more query-friendly format. This function only supports JSON objects with elements. It should be used together with LATERAL VIEW.
EXPLODE_JSON_OBJECT(<json>)
<json> JSON type, the content should be a JSON object.<json>. The column type is Nullable<Struct<String, JSON>>.<json> is NULL or not a JSON object (such as an array []), 0 rows are returned.<json> is an empty object (such as {}), 0 rows are returned.create table example( k1 int ) properties( "replication_num" = "1" ); insert into example values(1);
select * from example lateral view explode_json_object('{"k1": "v1", "k2": 123}') t2 as c;
+------+------------------------------+ | k1 | c | +------+------------------------------+ | 1 | {"col1":"k1", "col2":""v1""} | | 1 | {"col1":"k2", "col2":"123"} | +------+------------------------------+
select * from example lateral view explode_json_object('{"k1": "v1", "k2": 123}') t2 as k, v;
+------+------+------+ | k1 | k | v | +------+------+------+ | 1 | k1 | "v1" | | 1 | k2 | 123 | +------+------+------+
The type of
vis JSON
select * from example lateral view explode_json_object('{}') t2 as c;
Empty set (0.03 sec)
select * from example lateral view explode_json_object(NULL) t2 as c;
Empty set (0.03 sec)
select * from example lateral view explode_json_object('[]') t2 as c;
Empty set (0.03 sec)