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

相关推荐
我想我不够好。2 小时前
plc学习路线
学习·plc
Rock_yzh5 小时前
AI学习日记——Transformer的架构:编码器与解码器
人工智能·深度学习·神经网络·学习·transformer
小至尖尖5 小时前
fastdbchkrep项目(数据库自动生成巡检报告) open source
sql·sql优化
乔冠宇5 小时前
vue需要学习的点
前端·vue.js·学习
shenghaide_jiahu7 小时前
数学分析简明教程——2.2(未完)
学习
Brookty8 小时前
【算法】位运算| & ^ ~ -n n-1
学习·算法·leetcode·位运算
·云扬·8 小时前
MySQL主从数据一致性校验工具:pt-table-checksum 详解
数据库·sql·mysql
shenghaide_jiahu9 小时前
数学分析简明教程——1.4(未完)
学习
那我掉的头发算什么9 小时前
【数据库】事务
数据库·sql·mysql·github·数据库开发
tritone9 小时前
在优豆云的免费云服务器上开启MongoDB学习之旅
服务器·学习·mongodb