dolt icon indicating copy to clipboard operation
dolt copied to clipboard

sql.JsonDocument ToString returns strings without whitespaces

Open druvv opened this issue 2 years ago • 0 comments

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.

druvv avatar Jun 13 '22 22:06 druvv