当前位置:网站首页>MySQL fully parses json/ arrays
MySQL fully parses json/ arrays
2022-07-05 20:40:00 【1024 questions】
mysql analysis json Array
Go straight up demo
The following demo It can be copied directly to sql function
Let's analyze
mysql json The string is parsed into the corresponding field
resolvent :JSON_EXTRACT
resolvent :REPLACE
mysql analysis json Arraymysql stay 5.7 Start supporting json Parsed You can also parse arrays !
Go straight up demo SELECT Substr(col, 2, Length(col) - 2), Length(col) FROM (SELECT Json_extract(Json_extract(Json_extract(state, "$.tpl"),"$.items" ), "$[0].url") AS col FROM page ORDER BY id DESC LIMIT 100) t;
JSON_EXTRACT Can be parsed sql , tpl You are the one json Of key value
If it's an array , use $[*].url perhaps $[0].url Get all of value Or some subscript url
The following demo It can be copied directly to sql function select JSON_EXTRACT(JSON_EXTRACT(JSON_EXTRACT('{"tpl":{"items":[{"type":"image","config":{"expandable":true,"linkAble":true},"url":"https://fs.esf.fangdd.net/test/FiZ0OtkhTZoD7fOtkp55SnuLGiKu.png?imageView2/2/w/750","id":1542348252537},{"type":"image","config":{"expandable":true,"linkAble":true},"url":"https://fs.esf.fangdd.net/test/FlR1VDQWEzD406NosLFrJUez4g_X.png?imageView2/2/w/750","id":1542348263477},{"type":"image","config":{"expandable":true,"linkAble":true},"url":"https://fs.esf.fangdd.net/test/FhMuYkWvnoMbv8I1dlQbm1KaX5Kn.png?imageView2/2/w/750","id":1542348269599},{"type":"image","config":{"expandable":true,"linkAble":true},"url":"https://fs.esf.fangdd.net/test/FlgR4IUNElPbcgjN2re_9A8jX30v.png?imageView2/2/w/750","id":1542348276124},{"type":"image","config":{"expandable":true,"linkAble":true},"url":"https://fs.esf.fangdd.net/test/FpXF8ETHxU8aqriiKbsYDjnu2Xd5.png?imageView2/2/w/750","id":1542348282561},{"type":"image","config":{"expandable":true,"linkAble":true},"url":"https://fs.esf.fangdd.net/test/FkUz5m7Jd6kE2slSyreDucozc3XH.png?imageView2/2/w/750","id":1542348288150,"link":"http://www.baidu.com"}],"bottomItems":[],"title":"demo2","description":"","wxLogo":"","bodyStyleInline":{},"bg":"","bgType":"","bottomStyleInline":{},"bottomBg":"","bottomBgType":"","uuid":"aaef8dfe-256a-4559-aec9-95d1fcdcf830","activeItemsName":"items","activeImgType":"","authInfo":{"role_list":[{"name":"test","access_key_list":[]},{"name":" Reviewers ","access_key_list":[]}],"city_list":[],"userId":3108779,"userName":"zhangyusheng","email":"[email protected]","mobile":"123123","trueName":" Zhang Yusheng ","isEmployee":true}}}', "$.tpl"), "$.items"), "$[0].url");
Let's analyze original json by
{ "tpl":{ "items":[ { "type":"image", "config":{ "expandable":true, "linkAble":true }, "url":"https://fs.esf.fangdd.net/test/FiZ0OtkhTZoD7fOtkp55SnuLGiKu.png?imageView2/2/w/750", "id":1542348252537 }, { "type":"image", "config":{ "expandable":true, "linkAble":true }, "url":"https://fs.esf.fangdd.net/test/FlR1VDQWEzD406NosLFrJUez4g_X.png?imageView2/2/w/750", "id":1542348263477 }, { "type":"image", "config":{ "expandable":true, "linkAble":true }, "url":"https://fs.esf.fangdd.net/test/FhMuYkWvnoMbv8I1dlQbm1KaX5Kn.png?imageView2/2/w/750", "id":1542348269599 }, { "type":"image", "config":{ "expandable":true, "linkAble":true }, "url":"https://fs.esf.fangdd.net/test/FlgR4IUNElPbcgjN2re_9A8jX30v.png?imageView2/2/w/750", "id":1542348276124 }, { "type":"image", "config":{ "expandable":true, "linkAble":true }, "url":"https://fs.esf.fangdd.net/test/FpXF8ETHxU8aqriiKbsYDjnu2Xd5.png?imageView2/2/w/750", "id":1542348282561 }, { "type":"image", "config":{ "expandable":true, "linkAble":true }, "url":"https://fs.esf.fangdd.net/test/FkUz5m7Jd6kE2slSyreDucozc3XH.png?imageView2/2/w/750", "id":1542348288150, "link":"http://www.baidu.com" } ], "bottomItems":[ ], "title":"demo2", "description":"", "wxLogo":"", "bodyStyleInline":{ }, "bg":"", "bgType":"", "bottomStyleInline":{ }, "bottomBg":"", "bottomBgType":"", "uuid":"aaef8dfe-256a-4559-aec9-95d1fcdcf830", "activeItemsName":"items", "activeImgType":"", "authInfo":{ "role_list":[ { "name":"test", "access_key_list":[ ] }, { "name":" Reviewers ", "access_key_list":[ ] } ], "city_list":[ ], "userId":3108779, "userName":"zhangyusheng", "email":"[email protected]", "mobile":"23123", "trueName":" Zhang Yusheng ", "isEmployee":true } }}
$.tpl
Is to get tpl This key key
$[0].url
Is to get [{url:1},{url:2}] Of the first object in this array url value That is to say 1
Field name :mobile , Content :{"contactName":" paragraph XX","contactJobTitle":" To be confirmed ","contactMobile":"131XXXXXXX"}.
resolvent :JSON_EXTRACTperform SQL:
Query results :
The result is quoted , Can't really use .
resolvent :REPLACEperform SQL:
Query results :
Problem solving .
sql sentence :
SELECTREPLACE (JSON_EXTRACT (mobile, '$.contactName'),'"','') AS 'contactName',REPLACE (JSON_EXTRACT (mobile, '$.contactMobile'),'"','') AS 'contactMobile',REPLACE (JSON_EXTRACT (mobile, '$.contactJobTitle'),'"','') AS 'contactJobTitle'FROMcscw_clientWHEREid = 'XXXXXXXXXXXXXXX'
The above is personal experience , I hope I can give you a reference , I also hope you can support the software development network .
边栏推荐
- Applet event binding
- Mongodb basic exercises
- Abnova e (diii) (WNV) recombinant protein Chinese and English instructions
- AI automatically generates annotation documents from code
- 2022北京眼睛健康用品展,护眼产品展,中国眼博会11月举办
- document方法
- Abnova丨E (DIII) (WNV) 重组蛋白 中英文说明书
- 19 Mongoose模块化
- 3.3 project evaluation
- Graph embedding learning notes
猜你喜欢
Abnova e (diii) (WNV) recombinant protein Chinese and English instructions
AI automatically generates annotation documents from code
Chemical properties and application instructions of prosci Lag3 antibody
Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)
渗透创客精神文化转化的创客教育
CVPR 2022 | 常见3D损坏和数据增强
Fundamentals - configuration file analysis
死信队列入门(两个消费者,一个生产者)
Specification of protein quantitative kit for abbkine BCA method
Pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
随机推荐
Abnova e (diii) (WNV) recombinant protein Chinese and English instructions
Abnova CD81 monoclonal antibody related parameters and Applications
Where is a good stock account? Is online account manager safe to open an account
Leetcode (695) - the largest area of an island
19 Mongoose模块化
National Eye Care Education Conference, 2022 the Fourth Beijing International Youth eye health industry exhibition
Usaco3.4 "broken Gong rock" band raucous rockers - DP
Dry goods navigation in this quarter | Q2 2022
CTF逆向基础
Duchefa丨MS培养基含维生素说明书
14、Transformer--VIT TNT BETR
资源道具化
The Chinese Academy of Management Sciences gathered industry experts, and Fu Qiang won the title of "top ten youth" of think tank experts
Reinforcement learning - learning notes 4 | actor critical
Chemical properties and application instructions of prosci Lag3 antibody
王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
Typhoon is coming! How to prevent typhoons on construction sites!
y57.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(三十)
清除app data以及获取图标
CVPR 2022 | 常见3D损坏和数据增强