Do you understand that JSON means "JavaScript Object Name"? If you have JavaScript Object Notation hardcoded, then just lose the quotation marks and you'll end up with parsing, as the JavaScript parser will take care of that.
var jsonstr = "{prop1: 'val1', prop2: 'val2'}"; var parsed = {prop1: 'val1', prop2: 'val2'};
Easy, right? !! Maybe I don’t know something, but it’s quite difficult for me to understand how people write parsers in JavaScript for JavaScript ... Of course, if you are not sure about the safety of the source jsonstr comes from, then its evaluation right out of the box, maybe , not the best idea, but if you and only you control the source, and especially if you hard-code it, as was said in the question, then just lose the quote!
source share