MySQL JSON_SEARCH: Complete Guide
The JSON_SEARCH function in MySQL is used to find elements in a specified JSON document that contain a specific path and value. Its syntax is as follows:
JSON_SEARCH(json_doc, one_or_all, search_str[, escape_char[, path] ...])
- json_doc: JSON document to be searched.
- one_or_all: specify the type of search results, which can be ‘one’ or ‘all’, indicating whether to return only the first matching result or all matching results.
- search_str: the string to be searched.
- Escape character: a character used to represent another character in a string.
- path: an optional parameter that specifies the JSON path to search.
The JSON_SEARCH function returns a JSON path or an array containing JSON paths indicating the location of matching elements in the JSON document. If no matching elements are found, it returns NULL.