get_json_int
Description
Syntax:
INT get_json_int(VARCHAR json_str, VARCHAR json_path)
This function parses and fetches the integers of the specified path in the JSON string. json_path
must start with the $
symbol and use .
as the path splitter. If the path contains .
, you may put the path in double quotation marks. Please use [] to denote array subscripts (starting from 0). The path itself may not contain double quotation marks, comma, and square brackets. If the json_string
or json_path
is in the wrong format, or if the specified item cannot be found, the function will return NULL.
Example
- Get the value whose key is "k1"
mysql> SELECT get_json_int('{"k1":1, "k2":"2"}', "$.k1");
+--------------------------------------------+
| get_json_int('{"k1":1, "k2":"2"}', '$.k1') |
+--------------------------------------------+
| 1 |
+--------------------------------------------+
- Get the second element of the array whose key is "my. key"
mysql> SELECT get_json_int('{"k1":"v1", "my.key":[1, 2, 3]}', '$."my.key"[1]');
+------------------------------------------------------------------+
| get_json_int('{"k1":"v1", "my.key":[1, 2, 3]}', '$."my.key"[1]') |
+------------------------------------------------------------------+
| 2 |
+------------------------------------------------------------------+
- Get the first element in an array whose secondary path is k1. key - > K2
mysql> SELECT get_json_int('{"k1.key":{"k2":[1, 2]}}', '$."k1.key".k2[0]');
+--------------------------------------------------------------+
| get_json_int('{"k1.key":{"k2":[1, 2]}}', '$."k1.key".k2[0]') |
+--------------------------------------------------------------+
| 1 |
+--------------------------------------------------------------+
Keywords
GET_JSON_INT,GET,JSON,INT