Bug #70486 When using json_replace(), '}' of the end disappear.
Submitted: 2 Oct 2013 9:11 Modified: 6 Nov 2013 20:37
Reporter: Yoshiaki Yamasaki Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: JSON User-defined function ( UDF ) Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: Sveta Smirnova CPU Architecture:Any
Tags: JSON_UDF

[2 Oct 2013 9:11] Yoshiaki Yamasaki
Description:
When using json_replace(), '}' of the end disappear.

* I'm using JSON UDF from labs.mysql.com.
(mysql-json-udfs-0.2.0-labs-json-udfs-linux-glibc2.5-x86_64.tar.gz)

How to repeat:
mysql> create table json (id int auto_increment, col1 varchar(1000), primary key(id));
Query OK, 0 rows affected (0.03 sec)

mysql> insert into json(col1) values('{"id":1,"Name":"Farmer grandmas","price":50000,"Conditions":["farms",15]}');
Query OK, 1 row affected (0.00 sec)

mysql> select id,json_replace(col1,'Name','"grandmas"') from json where id=1;
+----+-------------------------------------------------------------------+
| id | json_replace(col1,'Name','"grandmas"')                            |
+----+-------------------------------------------------------------------+
|  1 | {"id":1,"Name":"grandmas","price":50000,"Conditions":["farms",15] |
+----+-------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>

======================================================
[Supplement]

The following case is no problem.

mysql> select id,json_replace(col1,'Conditions','1','20') from json where id=1;
+----+---------------------------------------------------------------------------+
| id | json_replace(col1,'Conditions','1','20')                                  |
+----+---------------------------------------------------------------------------+
|  1 | {"id":1,"Name":"Farmer grandmas","price":50000,"Conditions":["farms",20]} |
+----+---------------------------------------------------------------------------+
1 row in set (0.00 sec)

Although json_set() doesn't be used the following, json_set() behaves same.

mysql> select id,json_set(col1,'Name','"grandmas"') from json where id=1;
+----+-------------------------------------------------------------------+
| id | json_set(col1,'Name','"grandmas"')                                |
+----+-------------------------------------------------------------------+
|  1 | {"id":1,"Name":"grandmas","price":50000,"Conditions":["farms",15] |
+----+-------------------------------------------------------------------+
1 row in set (0.00 sec)

======================================================

Suggested fix:
Don't cut '}' of the end.
[2 Oct 2013 11:19] MySQL Verification Team
Hello Yoshiaki,

Thank you for the bug report and test case.
Verified as described.

Thanks,
Umesh
[6 Nov 2013 18:52] Sveta Smirnova
Workaround: add leading space after last curly bracket.

Bug #70576 was marked as duplicate of this one.
[6 Nov 2013 20:36] Sveta Smirnova
Posted by developer:
 
Fixed in versions 0.2.1 and 0.3