JSON_EXTRACT_STRING extracts the field specified by <json_path> from a JSON object and converts it to STRING type.
JSON_EXTRACT_STRING(<json_object>, <json_path>)
<json_object>: JSON type, the target parameter to extract from.<json_path>: String type, the JSON path to extract the target element from the target JSON.Nullable(STRING) Returns the extracted STRING value, returns NULL in some cases
<json_object> or <json_path> is NULL, returns NULL.<json_path> does not exist, returns NULL.<json_path> cannot be converted to STRING, returns NULL.CAST(JSON_EXTRACT(<json_object>, <json_path>) as STRING)So even if the object pointed to by
<json_path> is not of STRING type, as long as it supports conversion to STRING type, you can get the converted value.JSON_EXTRACT_ISNULL。SELECT json_extract_string('{"id": 123, "name": "doris"}', '$.name');
+---------------------------------------------------------------+ | json_extract_string('{"id": 123, "name": "doris"}', '$.name') | +---------------------------------------------------------------+ | doris | +---------------------------------------------------------------+
SELECT json_extract_string('{"id": 123, "name": "doris"}', '$.name2');
+----------------------------------------------------------------+ | json_extract_string('{"id": 123, "name": "doris"}', '$.name2') | +----------------------------------------------------------------+ | NULL | +----------------------------------------------------------------+
SELECT json_extract_string('{"id": 123, "name": "doris"}', NULl);
+-----------------------------------------------------------+ | json_extract_string('{"id": 123, "name": "doris"}', NULl) | +-----------------------------------------------------------+ | NULL | +-----------------------------------------------------------+
SELECT json_extract_string(NULL, '$.id2');
+------------------------------------+ | json_extract_string(NULL, '$.id2') | +------------------------------------+ | NULL | +------------------------------------+
SELECT json_extract_string('{"id": 123, "name": "doris"}','$.id');
+------------------------------------------------------------+ | json_extract_string('{"id": 123, "name": "doris"}','$.id') | +------------------------------------------------------------+ | 123 | +------------------------------------------------------------+
SELECT json_extract_string('{"id": null, "name": "doris"}','$.id');
+-------------------------------------------------------------+ | json_extract_string('{"id": null, "name": "doris"}','$.id') | +-------------------------------------------------------------+ | null | +-------------------------------------------------------------+