Menu

MariaDB JSON_UNQUOTE(): Syntax, Escapes and Examples

MariaDB JSON_UNQUOTE() removes the quotes from a JSON string and unescapes its special characters. It returns a string or NULL for a NULL argument. See the official MariaDB JSON_UNQUOTE reference.

Syntax

JSON_UNQUOTE(val)

val is the string or JSON value to unquote. If it is a JSON string literal, the function removes its surrounding double quotes and interprets its escape sequences. If it is not a JSON string, MariaDB passes it through unchanged. If the value begins and ends with double quotes but is not a valid JSON string literal, MariaDB raises an error.

If val is SQL NULL, the result is NULL.

Escape sequences and SQL mode

With the default SQL mode, MariaDB recognizes these escapes inside a JSON string:

Escape Character
\" Double quote
\\ Backslash
\b Backspace
\f Form feed
\n Line feed
\r Carriage return
\t Tab
\uXXXX A Unicode code point written with four hexadecimal digits

The NO_BACKSLASH_ESCAPES SQL mode changes how backslashes are interpreted. In that mode, these backslash sequences are treated literally. See MariaDB’s SQL mode reference.

Examples

Remove the JSON quotes around a string:

SELECT JSON_UNQUOTE('"abc"');
abc

You can also unquote a JSON string selected by JSON_EXTRACT():

SELECT JSON_UNQUOTE(JSON_EXTRACT('"abc"', '$'));
abc

JSON_UNQUOTE() also passes through a value that is not a JSON string literal:

SELECT JSON_UNQUOTE('abc');
abc

A NULL argument returns NULL:

SELECT JSON_UNQUOTE(NULL);
NULL