当前位置:网站首页>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 .
边栏推荐
猜你喜欢
composer安装报错:No composer.lock file present.
干货!半监督预训练对话模型 SPACE
Error in composer installation: no composer lock file present.
Browser rendering principle and rearrangement and redrawing
Precision epidemic prevention has a "sharp weapon" | smart core helps digital sentinels escort the resumption of the city
一文了解MySQL事务隔离级别
CMake教程Step4(安装和测试)
采用药丸屏的iPhone14或引发中国消费者的热烈抢购
Deeply cultivate 5g, and smart core continues to promote 5g applications
中国广电正式推出5G服务,中国移动赶紧推出免费服务挽留用户
随机推荐
菜刀,蚁剑,冰蝎,哥斯拉的流量特征
The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"
[729. My schedule I]
Embedded UC (UNIX System Advanced Programming) -2
Judge whether a string is a full letter sentence
时间戳strtotime前一天或后一天的日期
7. Scala class
Jarvis OJ simple network management protocol
Timestamp strtotime the day before or after the date
干货!半监督预训练对话模型 SPACE
WR | 西湖大学鞠峰组揭示微塑料污染对人工湿地菌群与脱氮功能的影响
【testlink】TestLink1.9.18常见问题解决方法
Embedded-c Language-1
【二叉树】根到叶路径上的不足节点
CMake教程Step5(添加系统自检)
齐宣王典故
Detailed explanation of printf() and scanf() functions of C language
[Jianzhi offer] 63 Maximum profit of stock
How does the outer disk futures platform distinguish formal security?
[Jianzhi offer] 66 Build product array