diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index b3478b29b2f..2f57231b755 100644 --- a/mysql-test/r/func_json.result +++ b/mysql-test/r/func_json.result @@ -165,6 +165,16 @@ json_object() select json_object("ki", 1, "mi", "ya"); json_object("ki", 1, "mi", "ya") {"ki": 1, "mi": "ya"} +create table t1 as select json_object('id', 87, 'name', 'carrot') as f; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f` varchar(32) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +select * from t1; +f +{"id": 87, "name": "carrot"} +drop table t1; select json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2"); json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2") 1 diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test index e3c0264c674..caa8b0bb29c 100644 --- a/mysql-test/t/func_json.test +++ b/mysql-test/t/func_json.test @@ -68,6 +68,10 @@ select json_remove(@j, '$.a'); select json_object(); select json_object("ki", 1, "mi", "ya"); +create table t1 as select json_object('id', 87, 'name', 'carrot') as f; +show create table t1; +select * from t1; +drop table t1; select json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2"); select json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2[1]"); diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index cc25a703575..cf6bae91fec 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -874,7 +874,7 @@ append_null: void Item_func_json_array::fix_length_and_dec() { - ulonglong char_length= 4; + ulonglong char_length= 2; uint n_arg; if (arg_count == 0) @@ -889,7 +889,7 @@ void Item_func_json_array::fix_length_and_dec() return; for (n_arg=0 ; n_arg < arg_count ; n_arg++) - char_length+= args[n_arg]->max_char_length() + 2; + char_length+= args[n_arg]->max_char_length() + 4; fix_char_length_ulonglong(char_length); tmp_val.set_charset(collation.collation);