当前位置:网站首页>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 .
边栏推荐
- PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
- [UE4] unrealinsight obtains the real machine performance test report
- Informatics Orsay all in one 1339: [example 3-4] find the post order traversal | Valley p1827 [usaco3.4] American Heritage
- Codeforces Round #804 (Div. 2) - A, B, C
- Propping of resources
- Y57. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (30)
- Classic implementation of the basic method of intelligent home of Internet of things
- Informatics Olympiad 1337: [example 3-2] word search tree | Luogu p5755 [noi2000] word search tree
- 当Steam教育进入个性化信息技术课程
- 3.3 project evaluation
猜你喜欢

14、Transformer--VIT TNT BETR

Duchefa MS medium contains vitamin instructions

Abnova DNA marker high quality control test program

物联网智能家居基本方法实现之经典

【愚公系列】2022年7月 Go教学课程 004-Go代码注释

Duchefa low melting point agarose PPC Chinese and English instructions

2022北京眼睛健康用品展,护眼产品展,中国眼博会11月举办

Enter the parallel world

重上吹麻滩——段芝堂创始人翟立冬游记

鸿蒙os第四次学习
随机推荐
Is it safe to open a stock account by mobile phone? My home is relatively remote. Is there a better way to open an account?
CVPR 2022 | common 3D damage and data enhancement
When JS method passes long type ID value, precision loss will occur
Enter the parallel world
Applet global configuration
CADD course learning (7) -- Simulation of target and small molecule interaction (semi flexible docking autodock)
Abnova丨荧光染料 620-M 链霉亲和素方案
Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms
Abnova丨E (DIII) (WNV) 重组蛋白 中英文说明书
Y57. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (30)
Practical demonstration: how can the production research team efficiently build the requirements workflow?
Is it safe to open an account online? Where can I get a low commission?
Usaco3.4 "broken Gong rock" band raucous rockers - DP
Mongodb/ document operation
鸿蒙os第四次学习
全国爱眼教育大会,2022第四届北京国际青少年眼健康产业展会
Make Jar, Not War
资源道具化
ProSci LAG3抗体的化学性质和应用说明
Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)