var jqxhr = $.getJSON( "main.json", function(data) rerevolve data;);var json;window.onload = function() var jsonTxt = jqxhr.responseText; json = JSON.parse(jsonTxt); ....But eextremely 10th attempt or so i get the complying with error:

Uncaptured SyntaxError: Unsupposed token u in JSON at position 0at JSON.parse ()at window.onfill (profile.js:8)It"s really annoying, bereason it will certainly leave my page blank. I perform think it has somepoint to do with me trying to parse the JSON wrong - or somepoint. I really do not recognize and I"m looking forward to any type of answer that might lead me to the deal with. Thank you.

You are watching: Unexpected token u in json at position 0



That unintended "u" is the initially letter of the string "undefined". It happens bereason your two asynchronous operations (i.e. loading the JSON and also loading the window) are racing to completion, and if the JSON isn"t loaded rapid sufficient, the window.onpack approach will certainly attempt to parse the JSON string that isn"t loaded yet.

A solution is to move the JSON loading inside the onfill even handler. In addition, the totality suggest of getJSON is that it already parses the response for you as a JSON object, so tright here is no require for JSON.parse():

window.onload = function() $.getJSON( "major.json", function(json) // procedure the outcomes right here );


Insert a shot catch block wright here the JSON.parse() is dubbed.

It is possible that the message itself is not JSON.

For instance...

I think this is the problem because if response message is undefined, the char "u" is at place 0. So JSON.parse() is working via a string. Not a javascript-object-notation text file.

if(response !== undefined) try // carry out parse catch(errror) console.error("Not a JSON response")


Thanks for contributing a response to Stack Overflow!

Please be sure to answer the question. Provide details and also share your research!

But avoid

Asking for assist, clarification, or responding to various other answers.Making statements based on opinion; back them up with referrals or individual experience.

See more: What Does It Mean When A Girl Calls You Honey ? What Does It Mean When A Girl Calls You Honey

To learn more, see our tips on composing excellent answers.

Blog post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of business, privacy policy and cookie plan

Not the answer you're looking for? Browse other concerns tagged javascript jkid or ask your very own question.


website architecture / logo design © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.9.13.40199

Your privacy

By clicking “Accept all cookies”, you agree Stack Exadjust deserve to store cookies on your device and discshed information in accordance via our Cookie Policy.