当前位置:网站首页>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_table
Query 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 .
边栏推荐
猜你喜欢
[729. My Schedule i]
The two ways of domestic chip industry chain go hand in hand. ASML really panicked and increased cooperation on a large scale
The survey shows that the failure rate of traditional data security tools in the face of blackmail software attacks is as high as 60%
NPM installation
Three traversal methods of binary tree
winedt常用快捷键 修改快捷键latex编译按钮
33:第三章:开发通行证服务:16:使用Redis缓存用户信息;(以减轻数据库的压力)
ECU introduction
7. Scala class
机器学习编译第2讲:张量程序抽象
随机推荐
兰空图床苹果快捷指令
URP下Alpha从Gamma空间到Linner空间转换(二)——多Alpha贴图叠加
【性能测试】全链路压测
Allusions of King Xuan of Qi Dynasty
[Web attack and Defense] WAF detection technology map
Is it safe for qiniu business school to open a stock account? Is it reliable?
Jarvis OJ Flag
Three traversal methods of binary tree
Embedded UC (UNIX System Advanced Programming) -1
[729. My Schedule i]
thinkphp模板的使用
Read the basic grammar of C language in one article
Writing method of twig array merging
启牛商学院股票开户安全吗?靠谱吗?
干货!半监督预训练对话模型 SPACE
【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试
CMake教程Step1(基本起点)
张平安:加快云上数字创新,共建产业智慧生态
时间戳strtotime前一天或后一天的日期
国产芯片产业链两条路齐头并进,ASML真慌了而大举加大合作力度