有一个很长的string
值,其中包含json
列表:
{"name":"jack","age":"38","city":"JP"},{"name":"lee","age":"42","city":"tjs"},{"name":"smith","age":"46","city":"kh"}
目标是提取name
的信息,因此结果为'jack,lee,smith'
。
我尝试get_json_object
,但它返回null
;我还尝试使用get_json_object
split
,但仍未使用...
Hive
中是否有可以实现此需求的合适功能?
答案 0 :(得分:1)
with t as (select '{"name":"jack","age":"38","city":"JP"},{"name":"lee","age":"42","city":"tjs"},{"name":"smith","age":"46","city":"kh"}' as myjson)
select get_json_object(concat('{"x":[',myjson,']}'),'$.x.name[*]') as names
from t
+------------------------+
| names |
+------------------------+
| ["jack","lee","smith"] |
+------------------------+
with t as (select '{"name":"jack","age":"38","city":"JP"},{"name":"lee","age":"42","city":"tjs"},{"name":"smith","age":"46","city":"kh"}' as myjson)
select translate(get_json_object(concat('{"x":[',myjson,']}'),'$.x.name[*]'),'[]"','') as names
from t
+----------------+
| names |
+----------------+
| jack,lee,smith |
+----------------+