mysql has json type. Starting from version 5.7, MySQL has introduced the JSON data type, which can directly manipulate json data; but below MySQL version 5.7, you need to rely on data types such as varchar or text to store data in JSON format in tables.
The JSON type in MySQL
json is a very useful data type in mysql5. Before 7, people used strings to store json, but there is a problem that json cannot be manipulated. After 5.7, json data can be directly manipulated.
- There is nothing to say about creating json. The length is 0 by default
- Update and insert can be inserted with string
- Query, personally don’t like to use The data is handed over to the background for processing, so let’s hand it over to the database. The example is as follows:
- A table in the database has a content_json field, which contains such data!
{ "bill": [ { "bill": [ { "id": "C81AEAD03F90000142E81B405F6FADC0", "uuid": "cfd872541b3b4507a50c2b2eda6bef28", "billid": "kjdzyljgmzsfzypj", "pageno": [], "billver": "V1", "billname": "New Test", "fjNumber": "", "trueName": "", "allPageno": [ { "top": 13, "left": 7 } ], "billValue": {}, "isOtherZL": "", "billNumber": "", "fjTMNumber": "" }, { "id": "C81AED69D6400001A07818551D9EBEC0", "uuid": "05d87c8052cd44209c684407d200b7ec", "billid": "opztsfpsgd", "pageno": [], "billver": "V1", "billname": "Invoice Purchase", "fjNumber": "", "trueName": "", "allPageno": [ { "top": 13, "left": 7 } ], "isOtherZL": "", "billNumber": "", "fjTMNumber": "" } ], "index": "", "dependBjBill": { "formula": "", "keyView": "" }, "codeCondition": { "formula": "", "keyView": "" }, "billRuleCondition": { "formula": "", "keyView": "" } }, { "bill": [ { "id": "C81AED84903000019B29EAB0196014CE", "uuid": "0d93fe614d09489cbad8fa5a3d160289", "billid": "kjdzcwgwht", "pageno": [], "billver": "V1", "billname": "Financial Advisor", "fjNumber": "", "trueName": "", "allPageno": [ { "top": 39, "left": 7 } ], "isOtherZL": "", "billNumber": "", "fjTMNumber": "" } ], "index": "", "dependBjBill": { "formula": "", "keyView": "" }, "codeCondition": { "formula": "", "keyView": "" }, "billRuleCondition": { "formula": "", "keyView": "" } } ], "questions": [], "relyonCondition": {} }
The structure is like this, we want to query the bottom uuid! According to the conditions, bill is an array. The bill inside is still an array, so how to check the bottom uuid?
I personally prefer to use a method like lambda. After all, this is a compelling and beautiful operation:
SELECT content_json->' ;$.bill[*].bill[*].uuid' from b WHERE JSON_CONTAINS(content_json->'$.bill[*].bill[*].uuid' ,'["cfd872541b3b4507a50c2b2eda6bef28"]')
Query result It is not acceptable that the parameter must be a json type string.
Recommended tutorial: mysql video tutorial
The above is whether mysql has a json type? For more details, please pay attention to other related articles on 1024programmer.com!