Reputation: 500
This throws: "Uncaught SyntaxError: Unexpected token n(…)" ...
var text = "notation: 'fixed', precision: 2";
JSON.parse("{" + text + "}");
No clue as to why or how to safely parse.
Upvotes: 1
Views: 630
Reputation: 77482
You have wrong JSON
, you should wrap keys to double quotes, like this
var text = "notation: 'fixed', precision: 2";
text = text.replace(/\'/g, '"').replace(/(\w+):/g, '"$1":');
console.log( JSON.parse("{" + text + "}") );
Upvotes: 1