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.
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.