Parse JSON Array and load into hive table

2019-07-21 10:05发布

问题:

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?

回答1:

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 |
+------+----------+


标签: json hive