-4

This is fraustating me for 5 hours and now i have to finally ask this question.

I am trying to parse JSON using Javascript, but i don't know why i am getting this error on Console:

Uncaught SyntaxError: Unexpected token (…)
(anonymous function) @ VM382:2InjectedScript._evaluateOn @ 
VM251:904InjectedScript._evaluateAndWrap @ VM251:837InjectedScript.evaluate 
@VM251:693

JSON : http://pastebin.com/DddXQj6d

JS Code:

var json=**big json**;
var obj=JSON.parse(json);

Tried:

JSON.stringify(json);

json= "'" + json+ "'";

Loading JSON from URL

Ashesh
  • 71
  • 2
  • 10

1 Answers1

1

According to JSONLint and the Pastebin that you posted, the JSON is invalid, mostly due to the use of \'. Once you replace all of them by ', it should work normally.

In your original JSON file there are probably going to be some occurrences of \\'. As a string they become \'.

If you’re using Linux, a simple

sed -i "s/\\\\\\\'/\'/g" yourJSONFile.json

on your file fixes everything.

JSONLint says “Valid JSON” then.

You can also try

JSON.parse(json.replace(/\\'/,'\''));
Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
  • https://stackoverflow.com/questions/19303617/unable-to-parse-json-data-that-includes-a-single-quote – misko321 Aug 25 '15 at 10:20