1. 程式人生 > 實用技巧 >dataworks----解析json資料格式

dataworks----解析json資料格式

select 
    a._id,
    b.*
    from (
    SELECT 
        _id,
        a.coupon_detail_list
    FROM ikunchi_bi.src_thirdhub_tradesold_jingdong_normal 
    LATERAL VIEW 
    explode(
            split(
                regexp_replace(
                    regexp_extract(
                        get_json_object(trade, 
'$.trade.couponDetailList') -- 獲取data陣列,格式[{json},{json}] ,'^\\[(.*?)\\]$' ,1 ) -- 刪除字串前後的[],格式{json},{json} ,'\\},\\{' , '}||{' , 0 ) -- 將josn字串中的分隔符代換成||,格式{json}||{json}
,'\\|\\|' ) -- 按||分隔符切割成一個hive陣列 ) a as coupon_detail_list )a lateral view json_tuple(a.coupon_detail_list, 'couponPrice', 'couponType', 'orderId', 'skuId' )b AS coupon_price --優惠金額 ,coupon_type --優惠型別 ,order_id --
訂單編號 ,sku_id --京東sku編號 ;