1,创建一个含有json的表
![](https://img.haomeiwen.com/i14824291/8095d6117c80807b.jpg)
2,插入含有json数组的记录
![](https://img.haomeiwen.com/i14824291/e425509a379f30eb.jpg)
3,插入含有json对象的记录
![](https://img.haomeiwen.com/i14824291/cee2721496dc35fc.jpg)
效果图
![](https://img.haomeiwen.com/i14824291/0be4deb24336a508.jpg)
查询记录
![](https://img.haomeiwen.com/i14824291/3916f312a15423cc.jpg)
查询它的key
![](https://img.haomeiwen.com/i14824291/980d3c543aab233c.jpg)
另外还有这几种用于查询数组的方式
![](https://img.haomeiwen.com/i14824291/adb61892e79d19cc.jpg)
![](https://img.haomeiwen.com/i14824291/3b604308518a4693.jpg)
JSON值的规范化
JSON会自动规范输入的内容
比如
![](https://img.haomeiwen.com/i14824291/20cc35df94f1a59d.jpg)
在这里因为Hobby出现的两次,所以JSON取了后面出现的值
又比如在插入记录的时候
![](https://img.haomeiwen.com/i14824291/24d49012c4ea65e9.jpg)
看到的表为
![](https://img.haomeiwen.com/i14824291/3c15805c4e9187bd.jpg)
合并数组
JSON_MERGE_PRESERVE()会把里面的数组依次连接起来
JSON_MERGE_PATCH()只会选择最后一个数组
![](https://img.haomeiwen.com/i14824291/c5535b34b479c01b.jpg)
![](https://img.haomeiwen.com/i14824291/48c8c79290733c45.jpg)
修改记录
JSON_SET()替换存在的记录的值,如果不存在,则添加
![](https://img.haomeiwen.com/i14824291/cc6ff9f2575d3481.jpg)
JSON_INSERT() 添加新值但不替换现有值
![](https://img.haomeiwen.com/i14824291/103d5341edb9a1b4.jpg)
JSON_REPLACE()替换现有值并忽略新值
![](https://img.haomeiwen.com/i14824291/f6fddefd5cf01f8e.jpg)
JSON_REMOVE()删除指定位置
![](https://img.haomeiwen.com/i14824291/c45130b44e1f8931.jpg)
网友评论