Product Solutions Support
Try MemSQL

JSON_ARRAY_CONTAINS_<type>

This is a set of three JSON functions, which return true if the given value is contained in the JSON array. JSON arrays are lists in this form:

["foo", "bar", "baz"]
["foo", 1, 2, 3]

Return Type

Examples

mysql> select json_array_contains_string('["foo", "bar", "baz"]', 'foo') as has_foo;
+---------+
| has_foo |
+---------+
|       1 |
+---------+

mysql> select json_array_contains_string('invalid', 'foo') as has_foo;
+---------+
| has_foo |
+---------+
|    NULL |
+---------+

mysql> select json_array_contains_double('["foo", 1, 2, 3]', 3) as has_three;
+-----------+
| has_three |
+-----------+
|         1 |
+-----------+

mysql> select json_array_contains_json('["foo", 1, true, 3]', 'true') as has_truth;
+-----------+
| has_truth |
+-----------+
|         1 |
+-----------+

mysql> select json_array_contains_json('["foo", {"a":"b"}, 4]', '{"a":"b"}') as has_map;
+---------+
| has_map |
+---------+
|       1 |
+---------+
Was this article useful?