Bug #113922 JSON_QUOTE - allow non-strings
Submitted: 8 Feb 1:33 Modified: 8 Feb 6:38
Reporter: Ryan Brothers Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: JSON Severity:S4 (Feature request)
Version:8.3.0 OS:Any
Assigned to: CPU Architecture:Any

[8 Feb 1:33] Ryan Brothers
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:

| 1             |

| JSON_QUOTE('abc') |
| "abc"             |

Thank you for your help.

How to repeat:
[8 Feb 6:38] MySQL Verification Team
Hello Ryan,

Thank you for the feature request!