Hive学习(14)json解析get_json_object()函数

一、语法

目的:在一个标准JSON字符串中,按照指定方式抽取指定的字符串。

string get_json_object(string <json>, string <path>)

参数说明

  1. json:必填。STRING类型。标准的JSON格式对象,格式为{Key:Value, Key:Value,...}。如果遇到英文双引号("),需要用两个反斜杠(\)进行转义。如果遇到英文单引号('),需要用一个反斜杠(\)进行转义。
  2. path:必填。STRING类型。表示在json中的path,以$开头。
  3. $:表示根节点。
  4. .或['']:表示子节点。
  5. *:返回整个数组。

二、例:在数据表test中有一列jsonData,其数据如下:

复制代码
jsonData = '{
	"ID":121,
	"message":{
		"name":"Asher",
		"location":[{"county":"浦东","city":"上海"},
					{"county":"西直门","city":"北京"}]
	}	
}'
  1. 提取jsonData第一层数据ID

    select get_json_object(jsonData,'$.ID') from test

    --输出

    121

  2. 提取jsonData第二层数据name

    select get_json_object(jsonData,'$.message.name') from test

    --输出

    Asher

  3. 提取jsonData第二层数据location的第一项

    select get_json_object(jsonData,'$.message.location[0]') from test

    --输出

    {"county":"浦东","city":"上海"}

  4. 提取jsonData第二层数据location的第一项的city

    select get_json_object(jsonData,'$.message.location[0].city') from test

    --输出

    上海

5.提取jsonData第三层数据city

复制代码
select get_json_object(jsonData,'$.message.location.city') from test

--输出
>["上海","北京"]

码字不易,喜欢请点赞,谢谢!!!😊

参考:

https://blog.csdn.net/Asher117/article/details/107984650

https://help.aliyun.com/zh/maxcompute/user-guide/get-json-object

相关推荐
fen_fen41 分钟前
学习笔记(32):matplotlib绘制简单图表-数据分布图
笔记·学习·matplotlib
尽兴-2 小时前
如何将多个.sql文件合并成一个:Windows和Linux/Mac详细指南
linux·数据库·windows·sql·macos
萝卜青今天也要开心5 小时前
2025年上半年软件设计师考后分享
笔记·学习
amazinging5 小时前
北京-4年功能测试2年空窗-报培训班学测开-第四十七天
python·学习·selenium
吃货界的硬件攻城狮5 小时前
【STM32 学习笔记】SPI通信协议
笔记·stm32·学习
一个天蝎座 白勺 程序猿5 小时前
Python练习(1)Python基础类型操作语法实战:20道实战题解与案例分析(上)
开发语言·python·学习
努力的小帅6 小时前
STM32单片机_3
stm32·单片机·嵌入式硬件·学习·stm32c8t6
Jet45056 小时前
第100+43步 ChatGPT学习:R语言实现特征选择曲线图
学习·chatgpt·r语言
xiyuping246 小时前
ROS1学习第二弹
学习·机器人