How to extract selected values from json string in Hive How to extract selected values from json string in Hive hadoop hadoop

How to extract selected values from json string in Hive


select col1, get_json_object(col2,'$.variable1') as variable1,get_json_object(col2,'$.variable2') as variable2,get_json_object(col2,'$.variable3') as variable3 from json_test

If you put your output into a table (say json_test), you can parse in this way. You can tweak your query too to obtain these results.

Output:

col1 |variable1 |variable2 |variable3 |-----|----------|----------|----------|A    |123       |456       |789       |B    |222       |333       |444       |


Step1:

create table in HIVEcreate table json_student(student string)  -----load data in this tablehive>select * from json_variable;`enter code here`       {"col1":"A","variable1":123,"variable2":456,"variable3":789}       {"col1":"B","variable1":222,"variable2":333,"variable3":444}

Step2:

create table  json_variable1(col1 string,variable1 int,variable2 int,variable3 int);

Step3:

insert overwrite table json_variable1 select get_json_object(variable,'$.col1'),get_json_object(variable,'$.variable1'),get_json_object(variable,'$.variable2'),get_json_object(variable,'$.variable3') from json_variable;hive> Select * from json_variable1;    A       123     456     789`    `B       222     333     444``