Bug #86866 | Use last-wins strategy for duplicate keys in JSON objects | ||
---|---|---|---|
Submitted: | 29 Jun 2017 9:09 | Modified: | 2 Aug 2017 7:42 |
Reporter: | Knut Anders Hatlen | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: JSON | Severity: | S3 (Non-critical) |
Version: | 8.0.2 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[29 Jun 2017 9:09]
Knut Anders Hatlen
[2 Aug 2017 7:42]
Jon Stephens
Documented fix as follows in the MySQL 8.0.3 changelog: If a JSON object contained multiple members with the same key name, MySQL kept the first member and discarded the remainder. This contradicts RFC 7159, which suggests that duplicate key names can be handled in one of the ways listed here: Report an error (or otherwise fail to parse the object) Report all of the name-value pairs, including duplicates Report the last name-value pair only When a JSON text is evaluated in JavaScript, the last name-value pair is kept if multiple pairs with the same name are specified. MySQL now does likewise, and implements the last of the three options just listed, as shown here: mysql> CREATE TABLE t1 (c1 JSON); mysql> INSERT INTO t1 VALUES ('{"x": 17, "x": "red", "x": [3, 5, 7]}'); mysql> SELECT c1 FROM t1; +------------------+ | c1 | +------------------+ | {"x": [3, 5, 7]} | +------------------+ The fix for this issue also corrects a failure in the MySQL 8.0 server to handle insertion into a JSON column of data containing JSON arrays as the values for multiple identical keys. Closed.