go-mysql-server
go-mysql-server copied to clipboard
sql.JsonDocument ToString returns strings without whitespaces
The sql.JsonDocument
ToString
method uses json.Marshall
. This returns a string without any extraneous whitespace. MySQL on the other hand uses whitespaces for legibility:
mysql> CREATE TABLE t1 (c1 JSON);
mysql> INSERT INTO t1 VALUES
> ('{"x": 17, "x": "red"}'),
> ('{"x": 17, "x": "red", "x": [3, 5, 7]}');
mysql> SELECT c1 FROM t1;
+------------------+
| c1 |
+------------------+
| {"x": "red"} |
| {"x": [3, 5, 7]} |
+------------------+
Notice that there is additional whitespace between the semicolon of a key/value pairs and between the comma of array elements.
In Dolt's new storage format, we use sql.JsonDocument for JSON columns. Previously we used json.NomsJson which implements ToString
correctly.