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

JSON_VALUE can work on invalid JSON

    XMLWordPrintable

Details

    Description

      In the knowledgebase, JSON_VALUE is listed as returning NULL if json_doc is not a valid JSON document. However if json_doc is invalid but path refers to a position before whatever makes the JSON document invalid, the scalar specified by the path is still returned.

      Test script:

      SET @json = '{"a":"z","b":y,"c":"x"}';
      SELECT JSON_VALID(@json), JSON_VALUE(@json, '$.a'), JSON_VALUE(@json, '$.b');
      

      Returns:

      +-------------------+--------------------------+--------------------------+
      | JSON_VALID(@json) | JSON_VALUE(@json, '$.a') | JSON_VALUE(@json, '$.b') |
      +-------------------+--------------------------+--------------------------+
      |                 0 | z                        | NULL                     |
      +-------------------+--------------------------+--------------------------+
      

      This might be considered 'good' behaviour, but if this won't be fixed; it might make sense to update the knowledgebase to note this in the return type. I discovered this when using the function in a check constraint where I needed it to be valid JSON and one of the scalar values to meet other criteria - in cases like that it would be good to know that JSON_VALID must be used as well.

      Attachments

        Activity

          People

            greenman Ian Gilfillan
            rmhumphries Robert Humphries
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.