Can someone help explain the following behavior? As near as I can tell, it looks like when a JSON object is assigned to a mysql variable, it may or may not be escaped depending upon the context.
So let's try it
mysql> CREATE TABLE `json_test` (`jdata` json DEFAULT NULL);
Query OK, 0 rows affected (0.09 sec)
mysql> SET @IV_PROP = JSON_OBJECT( "name", "supportsInvalidation", "type", "java.lang.Boolean", "privy", false);
Query OK, 0 rows affected (0.02 sec)
mysql> INSERT INTO json_test (jdata) VALUES(@IV_PROP);
Query OK, 1 row affected (0.02 sec)
mysql> SELECT * FROM json_test;
+-------------------------------------------------------------------------------+
| jdata |
+-------------------------------------------------------------------------------+
| {"name": "supportsInvalidation", "type": "java.lang.Boolean", "privy": false} |
+-------------------------------------------------------------------------------+
1 row in set (0.01 sec)
That looks cool to me. But then....
mysql> UPDATE json_test SET jdata = JSON_SET(jdata, "$", @IV_PROP);
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> SELECT * FROM json_test;
+-------------------------------------------------------------------------------------------+
| jdata |
+-------------------------------------------------------------------------------------------+
| "{\"name\": \"supportsInvalidation\", \"type\": \"java.lang.Boolean\", \"privy\": false}" |
+-------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
Much sadness, but to fix it
mysql> UPDATE json_test SET jdata = JSON_SET(jdata, "$", JSON_OBJECT( "name", "supportsInvalidation", "type", "java.lang.Boolean", "privy", false));
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> SELECT * FROM json_test;
+-------------------------------------------------------------------------------+
| jdata |
+-------------------------------------------------------------------------------+
| {"name": "supportsInvalidation", "type": "java.lang.Boolean", "privy": false} |
+-------------------------------------------------------------------------------+
1 row in set (0.00 sec)
So that kind of undermines the value of a variable, no?