Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>)

You are calling:

JSON.parse(scatterSeries)

But when you defined scatterSeries, you said:

var scatterSeries = []; 

When you try to parse it as JSON it is converted to a string (""), which is empty, so you reach the end of the string before having any of the possible content of a JSON text.

scatterSeries is not JSON. Do not try to parse it as JSON.

data is not JSON either (getJSON will parse it as JSON automatically).

ch is JSON … but shouldn't be. You should just create a plain object in the first place:

var ch = {
    "name": "graphe1",
    "items": data.results[1]
};

scatterSeries.push(ch);

In short, for what you are doing, you shouldn't have JSON.parse anywhere in your code. The only place it should be is in the jQuery library itself.


Remove this line from your code:

console.info(JSON.parse(scatterSeries));

I was trying to debug this same error (I was writing code in TypeScript), but no matter what I did, the error didn't go away, it was really persistent.

I tried to look into the solution in many blogs and also this SO thread. I tried everything and nothing worked out.

Finally, I saw that I created the required file named products.json in which I gave a single extra newline (meaning, previously the file had 1 empty line, now it had 2 empty lines) and was following good GitHub practices as mentioned here.

Because of that single extra newline in my products.json file, I wasted 2 hours fixing a bug that didn't exist in the first place.

Finally when I deleted the entire products.json file and re-ran the entire thing, I didn't get any runtime errors and everything was running without any problems.

What I learned by going through all this? It's that experience is the teacher of all things.