Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON.parse not having the expected behaviour

I'm trying to get a json request, sent by post, and do the JSON.parse on it. But this error happens:

Uncaught SyntaxError: Unexpected token m in JSON at position 2 at JSON.parse () at :1:19

The code below reproduces the error:

const string = '{ msg_reject: \'Rejeitado porque sim\', accept: 1, photo: \'FSADKJK23B1\' }'
const json = JSON.parse(string)

And that's the way I'm sending it in my post

{ msg_reject: 'Rejeitado porque sim', accept: 1, photo: 'FSADKJK23B1' }

Is there something wrong in the way I'm sending it?

like image 398
brubdeds brindeds Avatar asked Nov 27 '22 10:11

brubdeds brindeds


1 Answers

Properly formatted JSON strings have " double quotes around each key and each string value.

const string = '{ "msg_reject": "Rejeitado porque sim", "accept": 1, "photo": "FSADKJK23B1" }';
const json = JSON.parse(string);
console.log(json);
like image 179
CertainPerformance Avatar answered Dec 04 '22 06:12

CertainPerformance