Details
-
Bug
-
Status: Closed (View Workflow)
-
Minor
-
Resolution: Fixed
-
10.2.5
-
None
-
Linux CentOS 6.5
Description
When there are multiple attributes in a JSON object with the same name, which is allowed but discouraged in JSON, JSON_KEYS returns one entry for each duplicate:
MySQL [test]> select JSON_KEYS('{"c1": "value 1", "c1": "value 2"}'); |
+-------------------------------------------------+ |
| JSON_KEYS('{"c1": "value 1", "c1": "value 2"}') | |
+-------------------------------------------------+ |
| ["c1", "c1"] | |
+-------------------------------------------------+ |
MySQL 5.7 returns just the single key:
MySQL [test]> select JSON_KEYS('{"c1": "value 1", "c1": "value 2"}'); |
+-------------------------------------------------+ |
| JSON_KEYS('{"c1": "value 1", "c1": "value 2"}') | |
+-------------------------------------------------+ |
| ["c1"] | |
+-------------------------------------------------+ |
Multiple values for a single key are discouraged, but I think MySQL has the correct behavior as the JSON_KEYS function should return an array of the keys, and although "c1" in the example above exists twice in the object, it is the same key.