Example 2 – Accessing nested JSON documents with Hive (Hive 0.14 and later versions)

We will see how to query Nested JSON documents using HiveQL. Let's assume we want to access the following Sample-Json-complex.json file in HiveSample-Json-complex.json:

{"DocId":"Doc1","User1":{"Id":9192,"Username":"u2452","ShippingAddress":{"Address1":"6373 Sun Street","Address2":"apt 12","City":"Foster City","State":"CA"},"Orders":[{"ItemId":5343,"OrderDate":"12/23/2017"},{"ItemId":7362,"OrderDate":"12/24/2017"}]}} 

Load Sample-Json-simple.json into HDFS:

[root@sandbox ~]# hadoop fs -mkdir  /user/hive-complex-data/ 
[root@sandbox ~]# hadoop fs -put Sample-Json-complex.json /user/hive-complex-data/ 

Create an external Hive table, json_nested_table:

hive> CREATE ...

Get Modern Big Data Processing with Hadoop now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.