diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index 6ee49d68787..826514e89f3 100644 --- a/mysql-test/r/func_json.result +++ b/mysql-test/r/func_json.result @@ -90,7 +90,7 @@ json_contains_path('{"key1":1, "key2":[2,3]}', "aLl", "$.key1", "$.key2") 1 select json_extract('{"key1":"asd", "key2":[2,3]}', "$.key1"); json_extract('{"key1":"asd", "key2":[2,3]}', "$.key1") -asd +"asd" select json_extract('{"key1":"asd", "key2":[2,3]}', "$.keyX", "$.keyY"); json_extract('{"key1":"asd", "key2":[2,3]}', "$.keyX", "$.keyY") NULL @@ -102,7 +102,10 @@ json_extract('{"key1":5, "key2":[2,3]}', "$.key1", "$.key2") [5, [2,3]] select json_extract('{"key0":true, "key1":"qwe"}', "$.key1"); json_extract('{"key0":true, "key1":"qwe"}', "$.key1") -qwe +"qwe" +select json_extract(json_object('foo', 'foobar'),'$'); +json_extract(json_object('foo', 'foobar'),'$') +{"foo": "foobar"} select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.k1', 'word'); json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.k1', 'word') {"a":1, "b":{"c":1, "k1":"word"}, "d":[1, 2]} diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test index ffe48b0f9db..6505c6e5909 100644 --- a/mysql-test/t/func_json.test +++ b/mysql-test/t/func_json.test @@ -41,6 +41,7 @@ select json_extract('{"key1":"asd", "key2":[2,3]}', "$.keyX", "$.keyY"); select json_extract('{"key1":"asd", "key2":[2,3]}', "$.key1", "$.key2"); select json_extract('{"key1":5, "key2":[2,3]}', "$.key1", "$.key2"); select json_extract('{"key0":true, "key1":"qwe"}', "$.key1"); +select json_extract(json_object('foo', 'foobar'),'$'); select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.k1', 'word'); select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.d[3]', 3); diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index e0ff7b4507a..71042021fbd 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -427,8 +427,8 @@ String *Item_func_json_extract::val_str(String *str) json_engine_t je; bool multiple_values_found= FALSE; const uchar *value; - const char *first_value= NULL, *first_p_value; - uint n_arg, v_len, first_len, first_p_len; + const char *first_value= NULL; + uint n_arg, v_len, first_len; uint array_counters[JSON_DEPTH_LIMIT]; if ((null_value= args[0]->null_value)) @@ -487,13 +487,6 @@ String *Item_func_json_extract::val_str(String *str) */ first_value= (const char *) value; first_len= v_len; - /* - We need this as we have to preserve quotes around string - constants if we use the value to create an array. Otherwise - we get the value without the quotes. - */ - first_p_value= (const char *) je.value; - first_p_len= je.value_len; continue; } else @@ -519,7 +512,7 @@ String *Item_func_json_extract::val_str(String *str) if (multiple_values_found ? str->append("]") : - str->append(first_p_value, first_p_len)) + str->append(first_value, first_len)) goto error; /* Out of memory. */ return str;