Description:
This is a feature request.
Currently the function JSON_QUOTE only works on strings. I don't believe there is a function that can be used to correctly quote any field type, so that you don't need to figure out which fields need JSON_QUOTE and which don't. I feel it would be useful if there was a function that would look at the datatype of the field and decide how to quote it correctly. It seems that JSON_ARRAY is doing that logic internally:
> SELECT JSON_ARRAY(1, '2"3', 4);
+-------------------------+
| json_array(1, '2"3', 4) |
+-------------------------+
| [1, "2\"3", 4] |
+-------------------------+
In the above, the integers are left as is, but the strings are encoded.
Would it be possible to allow any field type to be passed to JSON_QUOTE, or create a new function JSON_ENCODE or similar that would do the logic that JSON_ARRAY seems to be doing individually for each field passed? For example:
> SELECT JSON_QUOTE(1);
+---------------+
| JSON_QUOTE(1) |
+---------------+
| 1 |
+---------------+
> SELECT JSON_QUOTE('abc');
+-------------------+
| JSON_QUOTE('abc') |
+-------------------+
| "abc" |
+-------------------+
Thank you for your help.
How to repeat:
.