JSON parsing string with apostrophe (Single Quote)

How to parse the next line

var a = JSON.parse('[' + '{"NoteName":"it my life","UserId":"100","NoteActive":true,"UserEmail":" admin@dev.xrc.com ","CreatedDate":"8/13/2012 1:47:35 PM"}' + ']'); 
+5
source share
3 answers

You just need to avoid it\'s single quote

 var a = JSON.parse('[' + '{"NoteName":"it\ my life","UserId":"100","NoteActive":true,"UserEmail":" admin@dev.xrc.com ","CreatedDate":"8/13/2012 1:47:35 PM"}' + ']'); console.log(a); 
+7
source

You can escape (interpret only as characters) quotation marks by using a backslash. "\" "or "\"

+2
source

Replace it's with it\'s

 '[' + '{"NoteName":"it\ my life","UserId":"100","NoteActive":true,"UserEmail":" admin@dev.xrc.com ","CreatedDate":"8/13/2012 1:47:35 PM"}' + ']' 
+2
source

Source: https://habr.com/ru/post/1233230/


All Articles