SQL reference (MySQL and MariaDB dialects)

JSON operators (->, ->> and MEMBER OF)

The MySQL operators col->'$.path', col->>'$.path' and value MEMBER OF(array), and what the MariaDB dialect does instead.

Syntax#

SQL
json_doc -> 'path'
json_doc ->> 'path'
value MEMBER OF (json_array)

Description#

  • doc -> '$.path' is JSON_EXTRACT(doc, '$.path').
  • doc ->> '$.path' is JSON_UNQUOTE(JSON_EXTRACT(doc, '$.path')): the value without the JSON quotes.
  • value MEMBER OF (array) is 1 if value is a member of the JSON array, 0 if not.

The path must be a string literal. The left side is a column or any expression that gives a JSON document. The paths are the ones of JSON functions.

Remarks#

  • MySQL only. The operators are read in the MySQL dialect. MariaDB does not have them, so the MariaDB dialect does not read them: use JSON_EXTRACT, JSON_UNQUOTE and JSON_VALUE, or JSON_CONTAINS/JSON_SEARCH instead of MEMBER OF.
  • Precedence. They bind tighter than every arithmetic operator, together with COLLATE.
  • Missing path. A path that finds nothing gives NULL.
  • Comparing. d->'$.a' = 2 compares the JSON value with a number; d->>'$.b' = 'y' compares text. The comparison of text ignores case, like all text comparisons.
  • Invalid document. A text that is not JSON is error 3141 in the MySQL dialect.

Examples#

SQL
CREATE TABLE j (id INT PRIMARY KEY, d JSON);
INSERT INTO j VALUES (1, '{"a": 1, "b": "x", "c": [1, 2, 3], "n": {"k": "v"}}'), (2, '{"a": 2, "b": "y"}');
SELECT id, d->'$.a', d->>'$.b', d->'$.b', d->'$.c[1]', d->>'$.n.k' FROM j;
SELECT id FROM j WHERE d->>'$.b' = 'y';
SELECT id FROM j WHERE d->'$.a' = 2;
SELECT 2 MEMBER OF('[1, 2, 3]'), 5 MEMBER OF('[1, 2, 3]'), 'a' MEMBER OF('["a", "b"]');
SELECT id FROM j WHERE 3 MEMBER OF(d->'$.c');
SELECT d->'$.zzz' FROM j WHERE id = 1;       -- NULL
```7.

## See also

* [JSON functions](/docs/sql-reference/json-functions)
* [JSON type](/docs/sql-reference/json-type)
* [Operators](/docs/sql-reference/operators)