Parse JSON Array and load into hive table

2019-07-21 10:32发布

I have a Json Array like as below

[{"Name":"xxxx","Machine":"Machine1"},{"Name":"yyyy","Machine":"Machine2"},{"Name":"zzzz","Machine":"Machine3"}]

I need to parse that data and load into a hive table like below

Name    Machine

xxxx    Machine1
yyyy    Machine2
zzzz    Machine3

could someone please help?

标签: json hive
1条回答
Root(大扎)
2楼-- · 2019-07-21 10:49
select  j.Name,j.Machine

from    jsonarray t
        lateral view explode(split(substr(t.json,2),'(?<=\\}),(?=\\{)')) e
        lateral view json_tuple(e.col,'Name','Machine') j as Name,Machine
;

+------+----------+
| name | machine  |
+------+----------+
| xxxx | Machine1 |
| yyyy | Machine2 |
| zzzz | Machine3 |
+------+----------+
查看更多
登录 后发表回答