Details
Description
Given this test data
CREATE TABLE json_test (a JSON, b JSON); |
 |
INSERT INTO json_test VALUES ("[1,2,3]", '{"a":"foo"}'); |
I can observe the following behavior:
MariaDB [bugs]> SELECT JSON_OBJECT("a", JSON_COMPACT(a)) FROM (SELECT * FROM json_test) AS json_test_values; |
+-----------------------------------+ |
| JSON_OBJECT("a", JSON_COMPACT(a)) | |
+-----------------------------------+ |
| {"a": [1,2,3]} | |
+-----------------------------------+ |
MariaDB [bugs]> SELECT JSON_OBJECT("a", JSON_COMPACT(a), "b", b) FROM (SELECT * FROM json_test) AS json_test_values; |
+-------------------------------------------+ |
| JSON_OBJECT("a", JSON_COMPACT(a), "b", b) | |
+-------------------------------------------+ |
| {"a": "[1,2,3]", "b": "{\"a\":\"foo\"}"} | |
+-------------------------------------------+ |
MariaDB [bugs]> SELECT JSON_OBJECT("a", JSON_COMPACT(a), "b", JSON_COMPACT(b)) FROM (SELECT * FROM json_test) AS json_test_values; |
+---------------------------------------------------------+ |
| JSON_OBJECT("a", JSON_COMPACT(a), "b", JSON_COMPACT(b)) | |
+---------------------------------------------------------+ |
| {"a": [1,2,3], "b": {"a":"foo"}} | |
+---------------------------------------------------------+ |
The output of `JSON_COMPACT(a)` is sometimes treated as JSON and sometimes as a plain string