1

The following code is throwing an error:

alert(JSON.parse('{"name":"Quick Write  \"English\"","category":"qwer"}'));
/*
{
    "name": "Quick Write  \"English\"",
    "category":"qwer"
}
*/

It says

Uncaught SyntaxError: Unexpected token E in JSON at position 23

How do I make escaped quotes work?

Jojo Mako
  • 123
  • 9

1 Answers1

3

I believe you can use double \ instead of \

let x = '{"name":"Quick Write  \\"English\\"","category":"qwer"}';
console.log(JSON.parse(x));
wakakak
  • 842
  • 5
  • 13
  • Yes! I forgot that what I type doesn't directly become a string. The first slash is taken as a modifier and is removed. – Jojo Mako Oct 07 '19 at 00:05