`VARCHAR json_extract(VARCHAR json_str, VARCHAR path[, VARCHAR path] ...))` JSON jsonb_extract(JSON j, VARCHAR json_path) BOOLEAN json_extract_isnull(JSON j, VARCHAR json_path) BOOLEAN json_extract_bool(JSON j, VARCHAR json_path) INT json_extract_int(JSON j, VARCHAR json_path) BIGINT json_extract_bigint(JSON j, VARCHAR json_path) LARGEINT json_extract_largeint(JSON j, VARCHAR json_path) DOUBLE json_extract_double(JSON j, VARCHAR json_path) STRING json_extract_string(JSON j, VARCHAR json_path)
json_extract functions extract field specified by json_path from JSON. A series of functions are provided for different datatype.
json path syntax:
Exception handling is as follows:
BOOLEAN json_exists_path(JSON j, VARCHAR json_path) STRING json_type(JSON j, VARCHAR json_path)
There are two extra functions to check field existence and type
refer to json tutorial for more.
mysql> SELECT json_extract('{"id": 123, "name": "doris"}', '$.id');
+------------------------------------------------------+
| json_extract('{"id": 123, "name": "doris"}', '$.id') |
+------------------------------------------------------+
| 123 |
+------------------------------------------------------+
1 row in set (0.01 sec)
mysql> SELECT json_extract('[1, 2, 3]', '$.[1]');
+------------------------------------+
| json_extract('[1, 2, 3]', '$.[1]') |
+------------------------------------+
| 2 |
+------------------------------------+
1 row in set (0.01 sec)
mysql> SELECT json_extract('{"k1": "v1", "k2": { "k21": 6.6, "k22": [1, 2] } }', '$.k1', '$.k2.k21', '$.k2.k22', '$.k2.k22[1]');
+-------------------------------------------------------------------------------------------------------------------+
| json_extract('{"k1": "v1", "k2": { "k21": 6.6, "k22": [1, 2] } }', '$.k1', '$.k2.k21', '$.k2.k22', '$.k2.k22[1]') |
+-------------------------------------------------------------------------------------------------------------------+
| ["v1",6.6,[1,2],2] |
+-------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
mysql> SELECT json_extract('{"id": 123, "name": "doris"}', '$.aaa', '$.name');
+-----------------------------------------------------------------+
| json_extract('{"id": 123, "name": "doris"}', '$.aaa', '$.name') |
+-----------------------------------------------------------------+
| [null,"doris"] |
+-----------------------------------------------------------------+
1 row in set (0.01 sec)
JSONB, JSON, json_extract, json_extract_isnull, json_extract_bool, json_extract_int, json_extract_bigint, json_extract_largeint,json_extract_double, json_extract_string, json_exists_path, json_type