Javascript fails to read this json string as it contains a single quote character which it sees as the end of the string.
How can I escape the single quote so that it is not seen as the end of the string?
var json = '{"1440167924916":{"id":1440167924916,"type":"text","content":"It's a test!"}}'; var parsed = JSON.parse(json);
In JSON, you don't need to escape single quotes inside a value that is enclosed with double-quotes. In the case that you have double quotes as part of a value (that is enclosed with double quotes) then you would need to escape them.
The JSON standard requires double quotes and will not accept single quotes, nor will the parser.
JSON names require double quotes.
Use a backslash to escape the character:
var json = '{"1440167924916":{"id":1440167924916,"type":"text","content":"It\'s a test!"}}'; var parsed = JSON.parse(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