Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql valid json causes Missing a comma or '}' after an object member

Tags:

json

mysql

I get the following exception:

    SQLSTATE[22032]: <<Unknown error>>: 3140 Invalid JSON text: "Missing a comma or '}' after an object member." at position 19 in value for column 'requests.calendar_attendee'. 
(SQL: UPDATE `requests` SET `calendar_attendee` = (CASE WHEN `id` = '31241690' THEN '{"firstName":"jon \"doe\""}' 
    ELSE `calendar_attendee` END), `updated_at` = (CASE WHEN `id` = '31241690' THEN '2022-11-17 20:48:36' 
    ELSE `updated_at` END) WHERE `id` IN("31241690");)

I am aware that using case when then does not make sense for this query. The actual query can have many more cases.

I don't understand what it is complaining about. The json is valid:

{"firstName":"jon \"doe\""}

like image 480
Chris Avatar asked Oct 20 '25 11:10

Chris


1 Answers

You need to escape the back slash as well:

Try: THEN '{"firstName":"jon \\"doe\\""}'

You can check it here: https://dev.mysql.com/doc/refman/5.7/en/json.html#json-values

search on that page for "escape"

like image 180
Jorge Campos Avatar answered Oct 23 '25 02:10

Jorge Campos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!