Let's say that we have the following table:
CREATE TABLE json_test (
json_col TEXT
) DEFAULT CHARSET=latin1;
INSERT INTO json_test VALUES ('{"key1":"Sí"}');
We can get the value of key1 by executing the following:
SELECT JSON_VALUE(json_col, '$.key1') FROM json_test;
And this works fine:
MariaDB [db1]> SELECT JSON_VALUE(json_col, '$.key1') FROM json_test;
+--------------------------------+
| JSON_VALUE(json_col, '$.key1') |
+--------------------------------+
| Sí |
+--------------------------------+
1 row in set (0.00 sec)
But if we combine this with string functions, then the character set gets messed up. For example, run the following queries instead:
SELECT REPLACE(JSON_VALUE(json_col, '$.key1'), 'null', '') FROM json_test;
SELECT CONCAT(json_value(json_col, '$.key1'), 'a') FROM json_test;
And we get something unexpected:
MariaDB [db1]> SELECT REPLACE(JSON_VALUE(json_col, '$.key1'), 'null', '') FROM json_test;
+-----------------------------------------------------+
| REPLACE(JSON_VALUE(json_col, '$.key1'), 'null', '') |
+-----------------------------------------------------+
| SÃ |
+-----------------------------------------------------+
1 row in set (0.00 sec)
MariaDB [db1]> SELECT CONCAT(json_value(json_col, '$.key1'), 'a') FROM json_test;
+---------------------------------------------+
| CONCAT(json_value(json_col, '$.key1'), 'a') |
+---------------------------------------------+
| SÃa |
+---------------------------------------------+
1 row in set (0.00 sec)
We can workaround this problem by explicitly converting the JSON_VALUE return value to a given character set:
MariaDB [db1]> SELECT REPLACE(CONVERT(JSON_VALUE(json_col, '$.key1') USING utf8), 'null', '') FROM json_test;
+-------------------------------------------------------------------------+
| REPLACE(CONVERT(JSON_VALUE(json_col, '$.key1') USING utf8), 'null', '') |
+-------------------------------------------------------------------------+
| Sí |
+-------------------------------------------------------------------------+
1 row in set (0.00 sec)
Elena Stepanova
made changes -
2018-07-31 21:04
Field
Original Value
New Value
Status
Open
[ 1
]
Confirmed
[ 10101
]
Elena Stepanova
made changes -
2018-07-31 21:05
Fix Version/s
10.2
[ 14601
]
Fix Version/s
10.3
[ 22126
]
Affects Version/s
10.2
[ 14601
]
Affects Version/s
10.3
[ 22126
]
Assignee
Alexander Barkov
[ bar
]
Alexander Barkov
made changes -
2018-08-03 06:23
Assignee
Alexander Barkov
[ bar
]
Alexey Botchkov
[ holyfoot
]
Alexey Botchkov
made changes -
2018-08-04 15:45
Status
Confirmed
[ 10101
]
In Progress
[ 3
]
Alexey Botchkov
made changes -
2018-08-05 15:08
issue.field.resolutiondate
2018-08-05 15:08:34.0
2018-08-05 15:08:34.499
Alexey Botchkov
made changes -
2018-08-05 15:08
Fix Version/s
10.2.17
[ 23111
]
Fix Version/s
10.2
[ 14601
]
Fix Version/s
10.3
[ 22126
]
Resolution
Fixed
[ 1
]
Status
In Progress
[ 3
]
Closed
[ 6
]
Sergei Golubchik
made changes -
2021-12-06 21:47
Workflow
MariaDB v3
[ 88674
]
MariaDB v4
[ 154739
]
{"report":{"fcp":1330.4000005722046,"ttfb":547.2000007629395,"pageVisibility":"visible","entityId":68957,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"6bbc2d81-76fc-4d96-b4b5-409a6b947648","navigationType":0,"readyForUser":1402.8000001907349,"redirectCount":0,"resourceLoadedEnd":1607.3000001907349,"resourceLoadedStart":552.6000003814697,"resourceTiming":[{"duration":258.69999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":552.6000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":552.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":811.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":260.1000003814697,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":552.8000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":552.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":812.9000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":313.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":553.1000003814697,"connectEnd":553.1000003814697,"connectStart":553.1000003814697,"domainLookupEnd":553.1000003814697,"domainLookupStart":553.1000003814697,"fetchStart":553.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":553.1000003814697,"responseEnd":866.8000001907349,"responseStart":866.8000001907349,"secureConnectionStart":553.1000003814697},{"duration":393.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":553.3000001907349,"connectEnd":553.3000001907349,"connectStart":553.3000001907349,"domainLookupEnd":553.3000001907349,"domainLookupStart":553.3000001907349,"fetchStart":553.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":553.3000001907349,"responseEnd":946.5,"responseStart":946.5,"secureConnectionStart":553.3000001907349},{"duration":396.9000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":553.5,"connectEnd":553.5,"connectStart":553.5,"domainLookupEnd":553.5,"domainLookupStart":553.5,"fetchStart":553.5,"redirectEnd":0,"redirectStart":0,"requestStart":553.5,"responseEnd":950.4000005722046,"responseStart":950.4000005722046,"secureConnectionStart":553.5},{"duration":397.3999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":553.6000003814697,"connectEnd":553.6000003814697,"connectStart":553.6000003814697,"domainLookupEnd":553.6000003814697,"domainLookupStart":553.6000003814697,"fetchStart":553.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":553.6000003814697,"responseEnd":951,"responseStart":951,"secureConnectionStart":553.6000003814697},{"duration":397.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":553.8000001907349,"connectEnd":553.8000001907349,"connectStart":553.8000001907349,"domainLookupEnd":553.8000001907349,"domainLookupStart":553.8000001907349,"fetchStart":553.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":553.8000001907349,"responseEnd":951.5,"responseStart":951.5,"secureConnectionStart":553.8000001907349},{"duration":459.4000005722046,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":554,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":554,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1013.4000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":398.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":554.1000003814697,"connectEnd":554.1000003814697,"connectStart":554.1000003814697,"domainLookupEnd":554.1000003814697,"domainLookupStart":554.1000003814697,"fetchStart":554.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":554.1000003814697,"responseEnd":952.4000005722046,"responseStart":952.4000005722046,"secureConnectionStart":554.1000003814697},{"duration":459.0999994277954,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":554.4000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":554.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1013.5,"responseStart":0,"secureConnectionStart":0},{"duration":398.8999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":554.6000003814697,"connectEnd":554.6000003814697,"connectStart":554.6000003814697,"domainLookupEnd":554.6000003814697,"domainLookupStart":554.6000003814697,"fetchStart":554.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":554.6000003814697,"responseEnd":953.5,"responseStart":953.5,"secureConnectionStart":554.6000003814697},{"duration":764.8999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":563.1000003814697,"connectEnd":563.1000003814697,"connectStart":563.1000003814697,"domainLookupEnd":563.1000003814697,"domainLookupStart":563.1000003814697,"fetchStart":563.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":563.1000003814697,"responseEnd":1328,"responseStart":1328,"secureConnectionStart":563.1000003814697},{"duration":1037.0999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":570.2000007629395,"connectEnd":570.2000007629395,"connectStart":570.2000007629395,"domainLookupEnd":570.2000007629395,"domainLookupStart":570.2000007629395,"fetchStart":570.2000007629395,"redirectEnd":0,"redirectStart":0,"requestStart":570.2000007629395,"responseEnd":1607.3000001907349,"responseStart":1607.3000001907349,"secureConnectionStart":570.2000007629395},{"duration":306.20000076293945,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1025.5,"connectEnd":1025.5,"connectStart":1025.5,"domainLookupEnd":1025.5,"domainLookupStart":1025.5,"fetchStart":1025.5,"redirectEnd":0,"redirectStart":0,"requestStart":1025.5,"responseEnd":1331.7000007629395,"responseStart":1331.7000007629395,"secureConnectionStart":1025.5},{"duration":317.19999980926514,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1319.3000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1319.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1636.5,"responseStart":0,"secureConnectionStart":0}],"fetchStart":1,"domainLookupStart":1,"domainLookupEnd":1,"connectStart":1,"connectEnd":1,"requestStart":349,"responseStart":548,"responseEnd":570,"domLoading":551,"domInteractive":1639,"domContentLoadedEventStart":1639,"domContentLoadedEventEnd":1688,"domComplete":1971,"loadEventStart":1971,"loadEventEnd":1971,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1609.9000005722046},{"name":"bigPipe.sidebar-id.end","time":1610.6000003814697},{"name":"bigPipe.activity-panel-pipe-id.start","time":1610.9000005722046},{"name":"bigPipe.activity-panel-pipe-id.end","time":1614.8000001907349},{"name":"activityTabFullyLoaded","time":1704.7000007629395}],"measures":[],"correlationId":"47a5ff34066512","effectiveType":"4g","downlink":9.4,"rtt":0,"serverDuration":132,"dbReadsTimeInMs":18,"dbConnsTimeInMs":27,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
JSON_EXTRACT, for example, works okay.