Here are specific reasons why this error SyntaxError: Unexpected end of input occurs.
- Missed closing parentheses, Quotes, or brackets.
- When we try to parse an empty JSON with JSON.parse() or $.parseJSON.
Reproduce the error
// Uncaught SyntaxError: Unexpected end of input
function sum(a, b) {
return a + b;
//forgot closing curly brace
if (true) {
// forgot closing curly brace
const array = [1, 2 // forgot closing square bracket
const object = { name: 'Diwakar' // forgot closing curly brace
For example, if you run the above file, you will get the following error.
Uncaught SyntaxError: Unexpected end of input
“Uncaught SyntaxError: Unexpected end of input” is generated when you try to parse a JSON that doesn’t have any data using the JSON.parse() function or $.parseJSON.
// Uncaught SyntaxError: Unexpected end of JSON input
console.log(JSON.parse(''));
console.log($.parseJSON(''));
To fix the SyntaxError: Unexpected end of input in JavaScript, check your whole code and find out if you are missing any brackets or parentheses. If this is the case, end each module that must be closed with proper parentheses.
Other solutions are the following:
- Wrap your parsing code inside the try/catch block.
- Check whether your JSON is returning a valid response from the server or not.
- If you want an empty response from the server, then there is no need to write parsing logic on your code. Instead, remove that from the code.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.