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

相关推荐
极地野狼 音乐哔哔几秒前
[MAF预定义的AIContextProvider-03]ChatHistoryMemoryProvider——赋予Agent从经验中学习的能力
学习·microsoft
oier_Asad.Chen2 小时前
【洛谷题解/AcWing题解】洛谷P4011 孤岛营救问题/AcWing1131拯救大兵瑞恩
数据结构·笔记·学习·算法·动态规划·图论·宽度优先
xxwl5852 小时前
Git 完整学习笔记:从入门到团队协作
笔记·git·学习
minglie12 小时前
zynq的xlnx_rebase_v5.4_2020.2分支打patch-5.4.3-rt1.patch.xz补丁
学习
涛声依旧393163 小时前
运维项目:InnoAI SQL 助手
运维·数据库·sql
醉城夜风~3 小时前
HTML常用标签详解学习博客:从基础标签到页面结构完整掌握
前端·学习·html
minglie14 小时前
蚂蚁S9矿板PS 内核定时器驱动
学习
脑子进水养啥鱼?4 小时前
where id > ‘5‘ 的查询 sql 查不到 id = ‘10‘ 的数据?
数据库·sql·postgresql
你想知道什么?4 小时前
决策树-学习笔记
笔记·学习·决策树
SunnyDays10114 小时前
Python 将 Excel(XLS/XLSX)转换为 JSON:导出工作簿、工作表、单元格区域与自定义 JSON 结构
python·json·excel·excel 转 json·导出 excel 到 json·xlsx 转 json·xls 转 json