escaped " in sql column of type json
Posted: 11 December 2020, 11:34
Hello,
i have a table with one column of type json. i use json_encode to create the value for the insert statement. This always worked very well, but now i have a string containg the character " like and that produces the folling Error:
Unexpected error: Error while processing SQL request (leto.boardgamearena.com via TCP/IP): INSERT INTO log (`turn`, `player_id`, `card_id`, `card_deck`, `action`, `action_arg`) VALUES (1, 2331792, 0, 0, 'option', '{"type":1,"args":{"msgActive":"Ginso1 wants to play The \"Smoking Gun\" tape. ${you} can react.","msgInactive":"${actplayer} can react","targets":[],"_private":{"active":{"options":[{"id":"13","role":0,"type":2},{"id":-1,"type":5,"text":"pass"}]}}},"card":"10","secType":0}') Invalid JSON text: "Missing a comma or '}' after an object member." at position 57 in value for column 'log.action_arg'.
I already have a workaround: It works when i change the column type to VARCHAR, but i would like to know if i could get it working with the json column.
i have a table with one column of type json. i use json_encode to create the value for the insert statement. This always worked very well, but now i have a string containg the character " like
Code: Select all
$name = 'The "Smoking Gun" tape'Unexpected error: Error while processing SQL request (leto.boardgamearena.com via TCP/IP): INSERT INTO log (`turn`, `player_id`, `card_id`, `card_deck`, `action`, `action_arg`) VALUES (1, 2331792, 0, 0, 'option', '{"type":1,"args":{"msgActive":"Ginso1 wants to play The \"Smoking Gun\" tape. ${you} can react.","msgInactive":"${actplayer} can react","targets":[],"_private":{"active":{"options":[{"id":"13","role":0,"type":2},{"id":-1,"type":5,"text":"pass"}]}}},"card":"10","secType":0}') Invalid JSON text: "Missing a comma or '}' after an object member." at position 57 in value for column 'log.action_arg'.
I already have a workaround: It works when i change the column type to VARCHAR, but i would like to know if i could get it working with the json column.