ThomasMX
ThomasMX

Reputation: 1811

mysql - avoid escaping double quotes in json functions

When I issue...

select JSON_REPLACE('{"tbl" : "cnf"}', '$', '{"tbl":"cnf4"}');

I get the following :

+--------------------------------------------------------+
| JSON_REPLACE('{"tbl" : "cnf"}', '$', '{"tbl":"cnf4"}') |
+--------------------------------------------------------+
| "{\"tbl\":\"cnf4\"}"                                   |
+--------------------------------------------------------+

And it gets stored in my database the same say, with backslashes. I want to have no backslashes in my database. How can I achieve that?

I expect a reponse like: {"tbl":"cnf4"}

Upvotes: 3

Views: 2562

Answers (2)

Eugene
Eugene

Reputation: 1013

This helped me to unescape when I pushed new object to an existing array

json_array_append(data, '$', cast(? as json))

Upvotes: 0

Dave Stokes
Dave Stokes

Reputation: 823

Wrap in JSON_UNQUOTE

select JSON_UNQUOTE(JSON_REPLACE('{"tbl" : "cnf"}', '$', '{"tbl":"cnf4"}'));
+----------------------------------------------------------------------+
| JSON_UNQUOTE(JSON_REPLACE('{"tbl" : "cnf"}', '$', '{"tbl":"cnf4"}')) |
+----------------------------------------------------------------------+
| {"tbl":"cnf4"}                                                       |
+----------------------------------------------------------------------+
1 row in set (0.0005 sec)

Upvotes: 2

Related Questions