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

dot and bracket can not be used in the JSON path

    XMLWordPrintable

Details

    Description

      Hi,

      I found that when using dots and brackets in the key of the JSON data, use the path in JSON_VALUE will return NULL. There is an example:

      SELECT 'dot_key' AS case_name,
             JSON_SEARCH('{"a.b":"x"}','one','x') AS path,
             JSON_VALUE('{"a.b":"x"}',
                        JSON_UNQUOTE(JSON_SEARCH('{"a.b":"x"}','one','x')))
               AS roundtrip_value; -- dot_key	"$.a.b"	NULL
       
      SELECT 'hyphen_key' AS case_name,
             JSON_SEARCH('{"a-b":"x"}','one','x') AS path,
             JSON_VALUE('{"a-b":"x"}',
                        JSON_UNQUOTE(JSON_SEARCH('{"a-b":"x"}','one','x')))
               AS roundtrip_value; -- hyphen_key	"$.a-b"	x
       
      SELECT 'bracket_key' AS case_name,
             JSON_SEARCH('{"a[0]":"x"}','one','x') AS path,
             JSON_VALUE('{"a[0]":"x"}',
                        JSON_UNQUOTE(JSON_SEARCH('{"a[0]":"x"}','one','x')))
               AS roundtrip_value; -- bracket_key	"$.a[0]"	NULL
      

      Attachments

        Issue Links

          Activity

            People

              gkodinov Georgi Kodinov
              ChiZhang Chi Zhang
              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.