Purpose
JSON_QUOTE() quotes a string as a JSON value by using double quotation marks (") to wrap the string and escapes inner quotation marks (') and other characters, and then returns the result as a utf8mb4 string.
You can use the function to generate a valid JSON string literal that is included in a JSON document.
Syntax
JSON_QUOTE(string)
Description
string specifies the string that you want to quote. If the argument is NULL, NULL is returned.
Examples
obclient> SELECT JSON_QUOTE('null'), JSON_QUOTE('"null"');
+--------------------+----------------------+
| JSON_QUOTE('null') | JSON_QUOTE('"null"') |
+--------------------+----------------------+
| "null" | "\"null\"" |
+--------------------+----------------------+
1 row in set
obclient> SELECT JSON_QUOTE('[1, 2, 3, 4, 5]');
+-------------------------------+
| JSON_QUOTE('[1, 2, 3, 4, 5]') |
+-------------------------------+
| "[1, 2, 3, 4, 5]" |
+-------------------------------+
1 row in set
obclient> SELECT JSON_QUOTE('{"name":sam, "scores":[100,200,300]}');
+----------------------------------------------------+
| JSON_QUOTE('{"name":sam, "scores":[100,200,300]}') |
+----------------------------------------------------+
| "{\"name\":sam, \"scores\":[100,200,300]}" |
+----------------------------------------------------+
1 row in set