当前位置:网站首页>About JSON parsing function JSON in MySQL_ EXTRACT
About JSON parsing function JSON in MySQL_ EXTRACT
2022-07-05 17:14:00 【1024 questions】
mysql json analytic function JSON_EXTRACT
Example
mysql5.7 json Format and json_extract Method
Data initialization
select sentence
Return result resolution
Usage analysis
mysql json analytic function JSON_EXTRACTMYSQl Its own analytic function JSON_EXTRACT, use JSON_EXTRACT The function parsed by the function will contain double quotation marks
Examplet_table Inside the watch source The fields are represented by json The value written in the format is
{ "info" : { "color" : " white ", "inner_color" : " Beige ", "number" : "12345678", "registration_date" : "2012-11" },"accessory" : [ "1", "4", "5", "6", "7", "8", "9", "10" ],"remark" : " test "}Inquire about color Do not remove the double quotation marks ,inner_color Remove the double quotation marks ,remark Remove double lead
select source->'$.info.color' as color,replace(source->'$.info.inner_color','"','') as inner_color,replace(source->'$.remark','"','') as remark from t_tableQuery results
| “ white ” | Beige | test |
json_test Table data ,id and jsonstr Field ( type json)
{ "no": "7", "title": " The way of exercise ", "content": [{ "text": " Your usual exercise and time ", "item1": [{ "text": " jogging / Step on it / Combination of walking and running ", "type": "select", "value": "selected" }, { "text": " Up and down stairs / Climbing the mountain ", "type": "multselect", "value": "selected" }], "item2": [{ "text": " jogging 222 Combination of walking and running ", "type": "text", "value": " jogging 2" }, { "text": " Up and down stairs / Climbing the mountain 2", "type": "number", "value": "33" }] }]}select sentence SELECT id, json_extract( t.jsonstr, '$.*' ), json_extract( t.jsonstr, '$.title' ) AS "title", json_extract( t.jsonstr, '$.content' ) AS "content" , json_extract( t.jsonstr, '$**.text' ) AS "text" , json_extract( t.jsonstr, '$.content[*].item1[*]' ) AS "item1" FROM json_test t; Return result resolution //json_extract( t.jsonstr, '$.*' ) return :["7", " The way of exercise ", [{"text": " Your usual exercise and time ", "item1": [{"text": " jogging / Step on it / Combination of walking and running ", "type": "select", "value": "selected"}, {"text": " Up and down stairs / Climbing the mountain ", "type": "multselect", "value": "selected"}], "item2": [{"text": " jogging 222 Combination of walking and running ", "type": "text", "value": " jogging 2"}, {"text": " Up and down stairs / Climbing the mountain 2", "type": "number", "value": "33"}]}]]//json_extract( t.jsonstr, '$.title' ) AS "title" return :" The way of exercise "//json_extract( t.jsonstr, '$.content' ) AS "content" return :[{"text": " Your usual exercise and time ", "item1": [{"text": " jogging / Step on it / Combination of walking and running ", "type": "select", "value": "selected"}, {"text": " Up and down stairs / Climbing the mountain ", "type": "multselect", "value": "selected"}], "item2": [{"text": " jogging 222 Combination of walking and running ", "type": "text", "value": " jogging 2"}, {"text": " Up and down stairs / Climbing the mountain 2", "type": "number", "value": "33"}]}]//json_extract( t.jsonstr, '$**.text' ) AS "text" return :[" Your usual exercise and time ", " jogging / Step on it / Combination of walking and running ", " Up and down stairs / Climbing the mountain ", " jogging 222 Combination of walking and running ", " Up and down stairs / Climbing the mountain 2"]//json_extract( t.jsonstr, '$.content[*].item1[*]' ) AS "item1" return :[{"text": " jogging / Step on it / Combination of walking and running ", "type": "select", "value": "selected"}, {"text": " Up and down stairs / Climbing the mountain ", "type": "multselect", "value": "selected"}] Usage analysis | ‘$.*’ | Return to all json |
| ‘$.title’ | return key=”title” The data of |
| ‘$**.text’ | Return to all the lowest levels key=”text” The data of |
| ‘$.content[*].item1[*]’ | return key=content Of list Of key=item1 Of list All of |
Official documents :https://dev.mysql.com/doc/refman/5.7/en/json.html
The above is personal experience , I hope I can give you a reference , I also hope you can support the software development network .
边栏推荐
- 美国芯片傲不起来了,中国芯片成功在新兴领域夺得第一名
- Wsl2.0 installation
- PHP人才招聘系统开发 源代码 招聘网站源码二次开发
- 机器学习01:绪论
- [729. My Schedule i]
- dried food! Semi supervised pre training dialogue model space
- Rider 设置选中单词侧边高亮,去除警告建议高亮
- thinkphp3.2.3
- Wechat official account web page authorization login is so simple
- ThoughtWorks global CTO: build the architecture according to needs, and excessive engineering will only "waste people and money"
猜你喜欢

China Radio and television officially launched 5g services, and China Mobile quickly launched free services to retain users

调查显示传统数据安全工具面对勒索软件攻击的失败率高达 60%

Etcd build a highly available etcd cluster

PHP talent recruitment system development source code recruitment website source code secondary development

【性能测试】jmeter+Grafana+influxdb部署实战

深耕5G,芯讯通持续推动5G应用百花齐放

基于51单片机的电子时钟设计

dried food! Semi supervised pre training dialogue model space

激动人心!2022开放原子全球开源峰会报名火热开启!

33:第三章:开发通行证服务:16:使用Redis缓存用户信息;(以减轻数据库的压力)
随机推荐
【性能测试】全链路压测
thinkphp3.2.3
高数 | 旋转体体积计算方法汇总、二重积分计算旋转体体积
Little knowledge about C language (array and string)
Embedded -arm (bare board development) -2
Embedded-c Language-4
C#(Winform) 当前线程不在单线程单元中,因此无法实例化 ActiveX 控件
Debug kernel code through proc interface
[wechat applet] read the life cycle and route jump of the applet
采用药丸屏的iPhone14或引发中国消费者的热烈抢购
C language to get program running time
Wsl2.0 installation
【729. 我的日程安排錶 I】
【剑指 Offer】66. 构建乘积数组
【微信小程序】一文读懂小程序的生命周期和路由跳转
Iphone14 with pill screen may trigger a rush for Chinese consumers
What is ROM
Wechat official account web page authorization login is so simple
【729. 我的日程安排表 I】
Jarvis OJ Flag