hive提供了json的解析函數:get_json_objectsql
對於jsonArray(json數組),如person表的xjson字段有數據:json
[{"name":"王二狗","sex":"男","age":"25"},{"name":"李狗嗨","sex":"男","age":"47"}]
取出第一個json對象,那麼hive sql爲:數組
SELECT get_json_object(xjson,"$.[0]") FROM person;
結果是:函數
{"name":"王二狗","sex":"男","age":"25"}
取出第一個json的age字段的值:spa
SELECT get_json_object(xjson,"$.[0].age") FROM person;
結果code
25
get_json_object(param1,"$.param2")
param1:須要解析的json字段對象
param2:遇到數組就用 [0,1,2...] 0,1,2是數組對應的元素,遇到jsonObject直接用 ".key"取出想要獲取的value。blog