close

[Solved] Uncaught (in promise) SyntaxError: Unexpected end of JSON input

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Uncaught (in promise) SyntaxError: Unexpected end of JSON input 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 Uncaught (in promise) SyntaxError: Unexpected end of JSON input Error Occurs?

Today I get the following error Uncaught (in promise) SyntaxError: Unexpected end of JSON input in javascript.

How To Solve Uncaught (in promise) SyntaxError: Unexpected end of JSON input Error ?

  1. How To Solve Uncaught (in promise) SyntaxError: Unexpected end of JSON input Error ?

    To Solve Uncaught (in promise) SyntaxError: Unexpected end of JSON input Error This can be because you're not sending any JSON from the server OR This can be because you're sending invalid JSON.
    Your code might look like res.end();

  2. Uncaught (in promise) SyntaxError: Unexpected end of JSON input

    To Solve Uncaught (in promise) SyntaxError: Unexpected end of JSON input Error This can be because you're not sending any JSON from the server OR This can be because you're sending invalid JSON.
    Your code might look like res.end();

Solution 1


This happened to me also when I was running a server with Express.js and using Brave browser. In my case it was the CORs problem. I did the following and it solved the problem in my case: (since this is an Express framework, I am using app.get)

-on the server side:

 res.set({
        "Content-Type": "application/json",
        "Access-Control-Allow-Origin": "*",
    });

-on client side I used Fetch to get data but disabled the CORS option

// mode: "no-cors" //disabled this in Fetch

That took care of my issues with fetching data with Express

Solution 2

This can be because you’re not sending any JSON from the server OR This can be because you’re sending invalid JSON.

Your code might look like res.end();

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