Bug #73486 JSON_SET, JSON_APPEND do not append to empty document
Submitted: 6 Aug 2014 13:02 Modified: 7 Aug 2014 12:56
Reporter: Sveta Smirnova Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: JSON User-defined function ( UDF ) Severity:S3 (Non-critical)
Version:0.3.1 OS:Any
Assigned to: Sveta Smirnova CPU Architecture:Any

[6 Aug 2014 13:02] Sveta Smirnova
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)
[7 Aug 2014 12:56] Sveta Smirnova
Posted by developer:
 
Fixed in version 0.3.2