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
;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM