Purpose
Strings are referenced as JSON values by enclosing them in double quotation marks and escaping any internal quotation marks or other special characters. The result is returned as a utf8mb4 string.
This function is typically used to generate valid JSON string literals for inclusion in JSON documents, facilitating processing.
Syntax
JSON_QUOTE(string)
Description
string indicates the string to reference. 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