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

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.