My question is related to this question jQuery.parseJSON single quote vs double quote. There are many topics on this issue, but I still don't know clean solution.
I dont have Jquery, and I am working in TypeScript (not JavaScript). But everythink else is same.
My question is: What if I have string with double qoute ?
How to resolve this problem ? Is there way to convert this in valid string type?
var obj = JSON.parse(data);
I will get error if json string is with double qoute.
SyntaxError: Unexpected token
Whole code is:
fs.readFile(templatePath, 'utf8', (err: Error, data: Object) => {
if (err) {
res.send(500);
}
try {
var obj = JSON.parse(data);
res.json(obj);
} catch (e) {
res.send(500);
}
});
Thanks for help.