hive> select get_json_object('{
> "store":
> {
> "fruit":[{"weight":8,"type":"apple"}, {"weight":9,"type":"pear"}],
> "bicycle":{"price":19.95,"color":"red"}
> },
> "email":"amy@only_for_json_udf_test.net",
> "owner":"amy"
> }','$.store.fruit[0].weight');
OK
8
Time taken: 0.141 seconds, Fetched: 1 row(s)
hive> select get_json_object('{
> "store":
> {
> "fruit":[{"weight":8,"type":"apple"}, {"weight":9,"type":"pear"}],
> "bicycle":{"price":19.95,"color":"red"}
> },
> "email":"amy@only_for_json_udf_test.net",
> "owner":"amy"
> }','$.store.fruit[1].type');
OK
pear
hive> select get_json_object('{
> "store":
> {
> "fruit":[{"weight":8,"type":"apple"}, {"weight":9,"type":"pear"}],
> "bicycle":{"price":19.95,"color":"red"}
> },
> "email":"amy@only_for_json_udf_test.net",
> "owner":"amy"
> }','$.store.fruit.type');
OK
["apple","pear"]
Time taken: 0.137 seconds, Fetched: 1 row(s)
get_json_object中对于外层的直接'$.key.key[index].key2'; index对应数组中第几个json,key2对应数组中json的key;
网友评论