Description:
Created from this comment: https://blogs.oracle.com/svetasmirnova/entry/json_udf_functions_version_03#comment-1406842...
Funcions JSON_SET and JSON_APPEND does not append elements to empty object.
How to repeat:
mysql> select json_set('{}', 'a', '"b"') ;
+----------------------------+
| json_set('{}', 'a', '"b"') |
+----------------------------+
| {} |
+----------------------------+
1 row in set (0.00 sec)
mysql> select json_append('{}', 'a', '"b"') ;
+-------------------------------+
| json_append('{}', 'a', '"b"') |
+-------------------------------+
| {} |
+-------------------------------+
1 row in set (0.00 sec)
mysql> select json_set('[]', 0, '"a"') ;
+--------------------------+
| json_set('[]', 0, '"a"') |
+--------------------------+
| [] |
+--------------------------+
1 row in set (0.00 sec)
mysql> select json_append('[]', 0, '"a"') ;
+-----------------------------+
| json_append('[]', 0, '"a"') |
+-----------------------------+
| [] |
+-----------------------------+
1 row in set (0.00 sec)
mysql> select json_append('[]', 1, '"a"') ;
+-----------------------------+
| json_append('[]', 1, '"a"') |
+-----------------------------+
| [] |
+-----------------------------+
1 row in set (0.00 sec)
mysql> select json_append('[]', -1, '"a"') ;
+------------------------------+
| json_append('[]', -1, '"a"') |
+------------------------------+
| [] |
+------------------------------+
1 row in set (0.00 sec)
Compare:
mysql> select json_set('{"c": "d"}', 'a', '"b"') ;
+------------------------------------+
| json_set('{"c": "d"}', 'a', '"b"') |
+------------------------------------+
| {"c": "d", "a": "b"} |
+------------------------------------+
1 row in set (0.00 sec)
mysql> select json_append('{"c": "d"}', 'a', '"b"') ;
+---------------------------------------+
| json_append('{"c": "d"}', 'a', '"b"') |
+---------------------------------------+
| {"c": "d", "a": "b"} |
+---------------------------------------+
1 row in set (0.00 sec)
mysql> select json_append('[1]', 1, '"a"') ;
+------------------------------+
| json_append('[1]', 1, '"a"') |
+------------------------------+
| [1, "a"] |
+------------------------------+
1 row in set (0.00 sec)
mysql> select json_set('[1]', 1, '"a"') ;
+---------------------------+
| json_set('[1]', 1, '"a"') |
+---------------------------+
| [1, "a"] |
+---------------------------+
1 row in set (0.00 sec)