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

JSON_OBJECT function generates "malformed" JSON with ZEROFILL type

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 10.4, 10.11.2, 10.7.8, 10.8.7, 10.9.5, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11, 11.0
    • 10.4, 10.5, 10.6, 10.11, 11.0, 11.1, 11.2
    • JSON
    • None

    Description

      When using the JSON_OBJECT function with ZEROFILL values, "malformed" JSON strings are generated, this occurs because it puts one or more 0s before the number. The JSON MariaDB own's functions fail to parse the string. Ej:

      CREATE OR REPLACE TEMPORARY TABLE tTest(
        id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
        zeroInt INT(2) UNSIGNED ZEROFILL
      );
       
      INSERT INTO tTest SET zeroInt = 1;
       
      SELECT JSON_OBJECT(
          'validProp1', 1,
          'zeroInt', zeroInt,
          'validProp2', 2
        ) INTO @json
        FROM tTest;
       
      SELECT
        @json,
        JSON_VALUE(@json, '$.validProp1') validProp1,
        JSON_VALUE(@json, '$.zeroInt') zeroInt,
        JSON_VALUE(@json, '$.validProp2') validProp2;
      

      Wich results in:

      +--------------------------------------------------+----------+-------+----------+
      | @json                                            |validProp1|zeroInt|validProp2|
      +--------------------------------------------------+----------+-------+----------+
      | {"validProp1": 1, "zeroInt": 01, "validProp2": 2}|1         |0      |          |
      +--------------------------------------------------+----------+-------+----------+
      

      The same JSON string also fails to parse with native Javascript JSON.parse() function.

      JSON.parse('{"validProp1": 1, "zeroInt": 01, "validProp2": 2}')
       
      > Uncaught SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 1 column 31 of the JSON data...
      

      Attachments

        Issue Links

          Activity

            People

              rucha174 Rucha Deodhar
              juanferrer Juan Ferrer Toribio
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.