Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
10.2.6
-
None
-
Windows 10
Description
It seems that JSON functions fail to get returned result from another function:
select json_extract(json_object('truc',json_array('machin',4,json_object('chose','XML'))),'$.truc[2].chose') as result;
|
+--------+
|
| result |
|
+--------+
|
| "XML" |
|
+--------+
|
|
select json_search(json_object('truc',json_array('machin',4,json_object('chose','XML'))),'one','XML') as Path;
|
+-------------------+
|
| Path |
|
+-------------------+
|
| "$.truc[2].chose" |
|
+-------------------+
|
|
select json_extract(json_object('truc',json_array('machin',4,json_object('chose','XML'))),json_search(json_object('truc',json_array('machin',4,json_object('chose','XML'))),'one','XML')) as Result;
|
+--------+
|
| Result |
|
+--------+
|
| NULL |
|
+--------+
|
Sould not the last query return "XML"?
Attachments
Issue Links
- relates to
-
MDEV-13794 JSON_SEARCH returns warning instead of error if given invalid data
-
- Closed
-
It seems that these functions have a general problem recognizing the type of their argument (JSON or not JSON?) for instance:
select json_array(5,json_array(1,2));
+-------------------------------+
| json_array(5,json_array(1,2)) |
+-------------------------------+
| [5, [1, 2]] |
+-------------------------------+
Normal, the return from JSON_ARRAY is a JSON item.
select json_array(5,'[1,2]');
+-----------------------+
| json_array(5,'[1,2]') |
+-----------------------+
| [5, "[1,2]"] |
+-----------------------+
This time, the function as regarded its second argument as a string.
select json_query('[1,2]','$');
+-------------------------+
| json_query('[1,2]','$') |
+-------------------------+
| [1,2] |
+-------------------------+
select json_array(5,json_query('[1,2]','$'));
+---------------------------------------+
| json_array(5,json_query('[1,2]','$')) |
+---------------------------------------+
| [5, "[1,2]"] |
+---------------------------------------+
This is wrong. The description of the JSON_QUERY function says
Given a JSON document, returns an object or array specified by the path. Returns NULL if not given a valid JSON document, or if there is no match.
Here the JSON_QUERY function, unlike the JSON_ARRAY one, has regarded its first argument as a valid JSON item since it did not return NULL. Therefore, according to the function description, it should have returned a JSON item like the JSON_ARRAY function does. But this time, its result has been regarded as a string. All this is not coherent.