close

[Solved] Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How To Solve Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse Error ?

  1. How To Solve Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse Error?

    To Solve Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse Error Remove this line from your code will solve your issue. console.info(JSON.parse(scatterSeries));

  2. Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse

    To Solve Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse Error Remove this line from your code will solve your issue. console.info(JSON.parse(scatterSeries));

Solution 1

What You are calling: is

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.

Solution 2

Remove this line from your code will solve your issue.

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

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment