MariaDB JSON_UNQUOTE() Function

In MariaDB, JSON_UNQUOTE() is a built-in function that de-quotes a JSON string and returns the result as a string.

MariaDB JSON_UNQUOTE() Syntax

Here is the syntax for the MariaDB JSON_UNQUOTE() function:

JSON_UNQUOTE(json_val)

Parameters

json_val

Required. a string.

If you supply the wrong number of arguments, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'JSON_UNQUOTE'.

Return value

The MariaDB JSON_UNQUOTE() function de-quotes JSON values ​​and returns the result as a string.

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

MariaDB recognizes the escape characters in the following table:

Escape sequence Sequence of characters
\" Double quotes "
\b backspace character
\f Form feed
\n line break
\r carriage return
\t Tabs
\\ backslash \
\uXXXX UTF-8 bytes of the Unicode value XXXX

MariaDB JSON_UNQUOTE() Examples

Basic example

This example shows how to use the JSON_UNQUOTE() function to strip double quotes around JSON string values.

SELECT JSON_UNQUOTE('"abc"');

Output:

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

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

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

Output:

+------------------------------------------+
| JSON_UNQUOTE(JSON_EXTRACT('"abc"', '$')) |
+------------------------------------------+
| abc                                      |
+------------------------------------------+

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

NULL parameter

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

SELECT JSON_UNQUOTE(NULL);

Output:

+--------------------+
| JSON_UNQUOTE(NULL) |
+--------------------+
| NULL               |
+--------------------+

Conclusion

In MariaDB, JSON_UNQUOTE() is a built-in function that de-quotes a JSON string and returns the result as a string.