hive处理JSON字符串,有固定的get_json_object函数可以使用
测试数据
{"store":{"fruit":[{"weight":8,"type":"apple"},{"weight":9,"type":"pear"}],"bicycle":{"price":19.951,"color":"red1"}},"email":"amy@only_for_json_udf_test.net","owner":"amy1"}
1、查找JSON中某个参数
select get_json_object('{"store":{"fruit":[{"weight":8,"type":"apple"},{"weight":9,"type":"pear"}],"bicycle":{"price":19.951,"color":"red1"}},"email":"amy@only_for_json_udf_test.net","owner":"amy1"}', '$.owner')
select get_json_object(data, '$.response') from jsontest limit 1;
2、查找JSON中数组元素,且支持嵌套。
select get_json_object('{"store":{"fruit":[{"weight":8,"type":"apple"},{"weight":9,"type":"pear"}],"bicycle":{"price":19.951,"color":"red1"}},"email":"amy@only_for_json_udf_test.net","owner":"amy1"}', '$.store.fruit[0].weight')
select get_json_object(data, '$.response.tags') from jsontest limit 1;
3、JSON格式的要求,必须是标准的JSON格式,且字符串用 "" 引起来