dolthub / dolt

Dolt – Git for Data
Apache License 2.0
17.58k stars 498 forks source link

Casting json to string doesn't escape double quotes in keys/values #7998

Open nicktobey opened 2 months ago

nicktobey commented 2 months ago

MySQL:

mysql> select cast(JSON_OBJECT('key"with"quotes', 1) as char);

+--------------------------+
| cast(@a as char)         |
+--------------------------+
| {"key\"with\"quotes": 1} |
+--------------------------+
1 row in set (0.00 sec)

mysql> select cast(cast(JSON_OBJECT('key"with"quotes', 1) as char) as json);

+---------------------------------------------------------------+
| cast(cast(JSON_OBJECT('key"with"quotes', 1) as char) as json) |
+---------------------------------------------------------------+
| {"key\"with\"quotes": 1}                                      |
+---------------------------------------------------------------+
1 row in set (0.00 sec)

Dolt:


> select cast(JSON_OBJECT('key"with"quotes', 1) as char);

+-------------------------------------------------+
| cast(JSON_OBJECT('key"with"quotes', 1) as char) |
+-------------------------------------------------+
| {"key"with"quotes": 1}                          |
+-------------------------------------------------+
1 row in set (0.00 sec)

> select cast(cast(JSON_OBJECT('key"with"quotes', 1) as char) as json);

expression 'convert(convert(json_object('key"with"quotes',1), char), json)': couldn't convert to json: Invalid JSON text: invalid character 'w' after object key