diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result
index 8a4405ac22d..d8d87b53672 100644
--- a/mysql-test/main/func_json.result
+++ b/mysql-test/main/func_json.result
@@ -1757,5 +1757,14 @@ JSON_INSERT(JSON_OBJECT(l1, l2, l3, l4), '$.k3', 'v3') JSON_SET(JSON_OBJECT(l1,
{"k1": "v1", "k2": "v2", "k3": "v3"} {"k1": "v1", "k2": "new v2"} {"k1": "v1", "k2": "new v2"}
DROP TABLE t;
#
+# MDEV-27412: JSON_TABLE doesn't properly unquote strings
+#
+SET @data = '[{"Data": ""}]';
+SELECT
+data
+FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;
+data
+
+#
# End of 10.6 tests
#
diff --git a/mysql-test/main/func_json.test b/mysql-test/main/func_json.test
index dcbbd6055b1..195f487879d 100644
--- a/mysql-test/main/func_json.test
+++ b/mysql-test/main/func_json.test
@@ -1189,6 +1189,18 @@ SELECT JSON_ARRAY_APPEND(JSON_ARRAY(l1, l2, l3, l4), '$[0]', 'k3'), JSON_ARRAY_I
SELECT JSON_INSERT(JSON_OBJECT(l1, l2, l3, l4), '$.k3', 'v3'),JSON_SET(JSON_OBJECT(l1, l2, l3, l4), '$.k2', 'new v2'),JSON_REPLACE(JSON_OBJECT(l1, l2, l3, l4), '$.k2', 'new v2') from t;
DROP TABLE t;
+
+--echo #
+--echo # MDEV-27412: JSON_TABLE doesn't properly unquote strings
+--echo #
+
+
+SET @data = '[{"Data": ""}]';
+
+SELECT
+ data
+FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;
+
--echo #
--echo # End of 10.6 tests
--echo #
diff --git a/sql/item_func.h b/sql/item_func.h
index 592bcb65a0e..bf3582ded03 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -35,6 +35,8 @@ extern "C" /* Bug in BSDI include file */
#include
+extern int st_append_json(String *s,
+ CHARSET_INFO *json_cs, const uchar *js, uint js_len);
class Item_func :public Item_func_or_sum
{
void sync_with_sum_func_and_with_field(List- &list);
diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc
index fc485c182cb..3755b880247 100644
--- a/sql/item_jsonfunc.cc
+++ b/sql/item_jsonfunc.cc
@@ -79,7 +79,7 @@ static inline bool append_simple(String *s, const uchar *a, size_t a_len)
Appends JSON string to the String object taking charsets in
consideration.
*/
-static int st_append_json(String *s,
+int st_append_json(String *s,
CHARSET_INFO *json_cs, const uchar *js, uint js_len)
{
int str_len= js_len * s->charset()->mbmaxlen;
diff --git a/sql/json_table.cc b/sql/json_table.cc
index 86f565aa561..8a3ca39f883 100644
--- a/sql/json_table.cc
+++ b/sql/json_table.cc
@@ -380,6 +380,8 @@ int ha_json_table::rnd_init(bool scan)
static void store_json_in_field(Field *f, const json_engine_t *je)
{
+ String res_tmp("", 0, je->s.cs);
+
switch (je->value_type)
{
case JSON_VALUE_NULL:
@@ -400,7 +402,8 @@ static void store_json_in_field(Field *f, const json_engine_t *je)
default:
break;
};
- f->store((const char *) je->value, (uint32) je->value_len, je->s.cs);
+ st_append_json(&res_tmp, je->s.cs, je->value, je->value_len);
+ f->store((const char *) res_tmp.ptr(), (uint32) res_tmp.length(), je->s.cs);
}