1. 程式人生 > >hive中解析json陣列

hive中解析json陣列

 

-- hive中解析json陣列
select
     t1.status
    ,substr(ss.col,1,10) as col
    ,t3.evcId
    ,t3.evcLicense
    ,t3.evcAddress
    ,t3.modelName
from (
    select 
         get_json_object(json,"$.status") as status
        ,split(
            regexp_replace(
                regexp_extract(
                    get_json_object(json,"$.data") 
-- 獲取data陣列,格式[{json},{json}] ,'^\\[(.+)\\]$' ,1 ) -- 刪除字串前後的[],格式{json},{json} ,'\\}\\,\\{' , '\\}\\|\\|\\{' ) -- 將josn字串中的分隔符代換成||,格式{json}||{json} ,'\\|\\|' ) as str -- 按||分隔符切割成一個hive陣列
from tmp_json_test ) t1 lateral view explode(t1.str) ss as col -- 將hive陣列轉成行 lateral view json_tuple(ss.col,'evcId','evcLicense','evcAddress','modelName') t3 as evcId,evcLicense,evcAddress,modelName ;