Hive_解析 get_json_object

get_json_object ( string json_string, string path )
说明: 
  • 第一个参数填写json对象变量,第二个参数使用$表示json变量标识,然后用 . 或 [] 读取对象或数组。
  • 如果输入的json字符串无效,那么返回NULL。 
  • 每次只能返回一个数据项。
举例: 
data 为 test表中的字段,数据结构如下:
复制代码
data =
{
"store":
        {
         "fruit":[{"weight":8,"type":"apple"}, {"weight":9,"type":"pear"}],  
         "bicycle":{"price":19.95,"color":"red"}
         }, 
 "email":"amy@only_for_json_udf_test.net", 
 "owner":"amy" 
}
复制代码
1. get 单层值
hive> select  get_json_object(data, '$.owner') from test;
结果:amy
 
2. get 多层值
hive> select  get_json_object(data, '$.store.bicycle.price') from test;
结果:19.95
3. get 数组值[]
hive> select  get_json_object(data, '$.store.fruit[0]') from test;
结果:{"weight":8,"type":"apple"}
 

原文地址:https://www.cnblogs.com/wulw829/p/11321442.html

posted on   ExplorerMan  阅读(129)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
历史上的今天:
2019-11-14 ubuntu-18.04 设置开机启动脚本
2019-11-14 web端调起Windows系统应用程序(exe执行文件),全面兼容所有浏览器

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示