How to search JSON data in MySQL? How to search JSON data in MySQL? json json

How to search JSON data in MySQL?


If you have MySQL version >= 5.7, then you can try this:

SELECT JSON_EXTRACT(name, "$.id") AS nameFROM tableWHERE JSON_EXTRACT(name, "$.id") > 3

Output:

+-------------------------------+| name                          | +-------------------------------+| {"id": "4", "name": "Betty"}  | +-------------------------------+


Please check MySQL reference manual for more details:
https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html


If your are using MySQL Latest version following may help to reach your requirement.

select * from products where attribs_json->"$.feature.value[*]" in (1,3)


I use this query

SELECT id FROM table_name WHERE field_name REGEXP '"key_name":"([^"])key_word([^"])"';orSELECT id FROM table_name WHERE field_name RLIKE '"key_name":"[[:<:]]key_word[[:>:]]"';

The first query I use it to search partial value. The second query I use it to search exact word.