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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With