考虑一个简单的json:

{"openid":"a43dd9f","unionid":"cae4332f"}

在hive中如何提取出这个json的key呢?一个思路是利用正则表达式替换,将非key的部分去除并设置一个分割符,最后切分这个字符串就可以得到json的key,如有特殊需要还可利用explode函数,将结果转为多行。

select
    explode(
        split(
            substr(
                regexp_replace(
                    '{"openid":"a43dd9f","unionid":"cae4332f"}',
                    '.*?"(\\w+)":".*?"\}?',
                    ',$1'
                ),
                2
            ),
            ','
        )
    );

 结果:

Hive 从json中提取出所有key

 

相关文章:

  • 2022-01-13
  • 2021-11-17
  • 2023-03-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-17
  • 2022-12-23
  • 2022-01-28
  • 2022-12-23
  • 2021-10-06
相关资源
相似解决方案