I have a json column day_data
which has data in json format. How do I achieve the expected output using Hive?
input:
{"_id":"1","name":"abc","attribs":[{"minutes":0,"name":"sedentary"},{"minutes":0,"name":"lightly"},{"minutes":0,"name":"fairly"},{"minutes":28,"name":"very"}],"validated":true}
output:
id name attrib_minutes attrib_name validated
1 abc 0 sedentary true
1 abc 0 lightly true
1 abc 0 fairly true
1 abc 28 very true
I am able to extract id, name and validated fields using get_json_object
command,
select
get_json_object(day_data,'$._id') as id,
get_json_object(day_data,'$.name') as name,
get_json_object(day_data,'$.validated') as validated
from temp_table;
How do I extract the nested json attributes (attrib_minutes and attrib_name)?