Purpose
Returns a string quoted as a JSON value by wrapping the string with double quotation marks and escaping internal quotes and other characters, and returns the result as a utf8mb4 string.
This function is typically used to generate valid JSON string literals for inclusion in JSON documents for easier processing.
Syntax
JSON_QUOTE(string)
Parameters
string specifies the string to quote. If the parameter 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
