this is the contents of a file named menu.json:
{ "name":"John", "city":"New York"} I want to use jquery to parse the json file into the console of Chrome
var res = $.getJSON("menu.json", function() {}) .done(function() { var obj = $.parseJSON(res); console.log(obj.name); }); For some reason, Chrome is saying "Uncaught SyntaxError: Unexpected token o in JSON at position 1"
I'm running the page in MAMP and in the network tab, I am able to see the json file that's been loaded correctly. Why is this error occurring. Any help is much appreciated!
getJSONparses the response before it is passed to the success callback. You don't have to parse it. Alsoresin your snippet is the promise returned from the getJSON call so that doesn't make sense that you are trying to parse that anyway