MySQL JSON_QUOTE() Function
In MySQL, the JSON_QUOTE() function wraps a value with double quote and returns it as a JSON string value.
This function is often used to produce a valid JSON string literal.
JSON_QUOTE() Syntax
Here is the syntax of the MySQL JSON_QUOTE() function:
JSON_QUOTE(str)
Parameters
str- Required. A string.
Return value
The JSON_QUOTE() function wraps a value with double quote and returns it as a JSON string value.
If the argument is NULL, the JSON_QUOTE() function returns NULL.
These certain special characters in the following table are escaped with backslashes.
| 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_QUOTE() Examples
Here are some examples of JSON_QUOTE().
SELECT
JSON_QUOTE('123'),
JSON_QUOTE('NULL'),
JSON_QUOTE('"NULL"');
+-------------------+--------------------+----------------------+
| JSON_QUOTE('123') | JSON_QUOTE('NULL') | JSON_QUOTE('"NULL"') |
+-------------------+--------------------+----------------------+
| "123" | "NULL" | "\"NULL\"" |
+-------------------+--------------------+----------------------+