Single quotes in json value

Javascript cannot read this json string, because it contains a single quote character, which it sees as the end of the string.

How can I avoid a single quote so that it is not considered to be the end of a line?

var json = '{"1440167924916":{"id":1440167924916,"type":"text","content":"It a test!"}}'; var parsed = JSON.parse(json); 
+8
json javascript
source share
3 answers

Use backslash to remove character :

 var json = '{"1440167924916":{"id":1440167924916,"type":"text","content":"It\ a test!"}}'; var parsed = JSON.parse(json); 
+10
source share

Just avoid a single backslash quote like \' :

 var json = '{"1440167924916":{"id":1440167924916,"type":"text","content":"It\ a test!"}}'; var parsed = JSON.parse(json); //Output parsed to the document using JSON.stringify so it human-readable and not just "[object Object]": document.write(JSON.stringify(parsed)); 
+5
source share

Backslash Escape

 var json = '{"1440167924916":{"id":1440167924916,"type":"text","content":"It\ a test!"}}'; var parsed = JSON.parse(json); 
0
source share

All Articles