SyntaxStudy
Sign Up
MySQL Searching JSON with JSON_SEARCH
MySQL Intermediate 4 min read

Searching JSON with JSON_SEARCH

JSON_SEARCH

JSON_SEARCH() finds the path of a value within a JSON document. Returns the path or NULL if not found.

Example
SELECT JSON_SEARCH(
  '{"colors": ["red", "blue", "green"]}',
  'one',     -- "one" = first match, "all" = all matches
  'blue'
);
-- Returns: "$.colors[1]"
Pro Tip

JSON_SEARCH supports LIKE-style wildcards: JSON_SEARCH(doc, "one", "%ue").