-4

I am having problem converting a JSON String into Javascript object.

I ran into a few suggestions which said that I should not be using multi-line string but using single line string too did not work.

Snippet: https://jsfiddle.net/ankschoubey/hjh2d3z6/

SyntaxError: Unexpected token F in JSON at position 4536

Ankush
  • 1
  • 1

1 Answers1

2

Because you're including JSON as a JavaScript string value, you'll have to double-up on all the embedded backslash characters because they'll be parsed twice: first when the JavaScript parser reads the overall string constant to create the string value, and then again when you call JSON.parse().

Thus that portion of the string with \" should be \\". That way, the JavaScript string parsing will turn \\" into just \", and that's what will make the JSON parser happy.

Pointy
  • 405,095
  • 59
  • 585
  • 614