docs/en/sql-reference/sql-functions/json-functions/json-query-and-processing-functions/get_json_string.md
Analyzes and gets strings from the specified path (json_path) in a JSON string. If the format of json_string or json_path is wrong or if no matching value is found, this function will return NULL.
:::tip All of the JSON functions and operators are listed in the navigation and on the overview page
Accelerate your queries with generated columns :::
The alias is get_json_object.
VARCHAR get_json_string(VARCHAR json_str, VARCHAR json_path)
json_str: the JSON string. Supported data type is VARCHAR.json_path: the JSON path. Supported data type is VARCHAR. json_path starts with $ and uses . as the path separator. [ ] is used as the array subscripts which starts from 0. For example, $."my.key"[1] indicates to obtain the second value form element my.key.Returns a value of the VARCHAR type. If no matching object is found, NULL is returned.
k1.SELECT get_json_string('{"k1":"v1", "k2":"v2"}', "$.k1");
+---------------------------------------------------+
| get_json_string('{"k1":"v1", "k2":"v2"}', '$.k1') |
+---------------------------------------------------+
| v1 |
+---------------------------------------------------+
a from the first element.SELECT get_json_object('[{"a":"123", "b": "456"},{"a":"23", "b": "56"}]', '$[0].a');
+------------------------------------------------------------------------------+
| get_json_object('[{"a":"123", "b": "456"},{"a":"23", "b": "56"}]', '$[0].a') |
+------------------------------------------------------------------------------+
| 123 |
+------------------------------------------------------------------------------+
my.keySELECT get_json_string('{"k1":"v1", "my.key":["e1", "e2", "e3"]}', '$."my.key"[1]');
+------------------------------------------------------------------------------+
| get_json_string('{"k1":"v1", "my.key":["e1", "e2", "e3"]}', '$."my.key"[1]') |
+------------------------------------------------------------------------------+
| e2 |
+------------------------------------------------------------------------------+
k1.key -> k2.SELECT get_json_string('{"k1.key":{"k2":["v1", "v2"]}}', '$."k1.key".k2[0]');
+-----------------------------------------------------------------------+
| get_json_string('{"k1.key":{"k2":["v1", "v2"]}}', '$."k1.key".k2[0]') |
+-----------------------------------------------------------------------+
| v1 |
+-----------------------------------------------------------------------+
k1 from the array.SELECT get_json_string('[{"k1":"v1"}, {"k2":"v2"}, {"k1":"v3"}, {"k1":"v4"}]', '$.[*].k1');
+-------------------------------------------------------------------------------------+
| get_json_string('[{"k1":"v1"}, {"k2":"v2"}, {"k1":"v3"}, {"k1":"v4"}]', '$.[*].k1') |
+-------------------------------------------------------------------------------------+
| ["v1", "v3", "v4"] |
+-------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
GET_JSON_STRING,GET,JSON,STRING