Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse JSON Array and load into hive table

Tags:

json

hive

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?

like image 976
Shalaj Avatar asked Dec 09 '25 12:12

Shalaj


1 Answers

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 |
+------+----------+
like image 72
David דודו Markovitz Avatar answered Dec 12 '25 07:12

David דודו Markovitz