Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-12789

JSON_KEYS returns duplicate keys twice

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 10.2.5
    • Fix Version/s: 10.2.8
    • Component/s: JSON
    • Labels:
      None
    • Environment:
      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.

        Attachments

          Activity

            People

            Assignee:
            holyfoot Alexey Botchkov
            Reporter:
            karlsson Anders Karlsson
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: