Purpose
You can call this function to quote a string as a JSON value by using double quotation marks (") to wrap the string and escape inner quotation marks (') and other characters, and then return 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)
Notes
string specifies the string that you want to quote. If the argument is NULL, the return value is NULL.
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