MySQL JSON_UNQUOTE() Function

In MySQL, the JSON_UNQUOTE() function unquotes a JSON value and returns the result as a utf8mb4 string.

JSON_UNQUOTE() Syntax

Here is the syntax of the MySQL JSON_UNQUOTE() function:

JSON_UNQUOTE(json_val)

Parameters

json_val
Required. A string representing .

Return value

The JSON_UNQUOTE() function unquotes a JSON value and returns the result as a utf8mb4 string.

If the argument is NULL, the JSON_UNQUOTE() function returns NULL.

If the value begins and ends with double quotes, but is not a valid JSON string literal, MySQL will return an error like: ERROR 3141 (22032): Invalid JSON text in argument 1 to function json_unquote: xxx..

JSON_UNQUOTE() Special Character Escape Sequences:

Escape Sequence Character Represented by Sequence
\" A double quote (") character
\b A backspace character
\f A formfeed character
\n A newline (linefeed) character
\r A carriage return character
\t A tab character
\\ A backslash (\) character
\uXXXX UTF-8 bytes for Unicode value XXXX

JSON_UNQUOTE() Examples

This example shows how to use the JSON_UNQUOTE() function to unquotes a JSON string value.

SELECT JSON_UNQUOTE('"abc"');
+-----------------------+
| JSON_UNQUOTE('"abc"') |
+-----------------------+
| abc                   |
+-----------------------+

You can also pass a parameter of type JSON, for example:

SELECT JSON_UNQUOTE(CAST('"abc"' AS JSON));
+-----------------------+
| JSON_UNQUOTE('"abc"') |
+-----------------------+
| abc                   |
+-----------------------+

Here, we use the CAST() function to convert a string to JSON type.