Unexpected end of JSON input
Unexpected end of JSON input
This error means the JSON parser reached the end of the input string before the structure was complete. Either the input is an empty string, the JSON was truncated mid-stream (a common network issue), or an opening bracket or quote was never closed. It is one of the most-searched JSON errors because it can be caused by everything from a clipped clipboard paste to a partially written config file.
Empty string passed to JSON.parse
Passing an empty string is the simplest trigger. JSON requires at least one value — an empty string is not valid JSON. Validate that the string has content before parsing.
Invalid
JSON.parse("") // throwsValid
const text = ""
if (text.trim()) {
JSON.parse(text)
}Truncated HTTP response body
A network timeout, dropped connection, or a server that closes the socket early can deliver a partial JSON body. The symptom is that the JSON starts correctly (you see opening braces) but the parser hits the end of the buffer unexpectedly. Always stream or read the full response and handle the error.
Invalid
// Server sends: {"items":[{"id":1},{"id":2
// Connection dropped — truncated inputValid
// Always check Content-Length / use response.json() // and handle parse errors with try/catch
Missing closing bracket or brace
Hand-written or templated JSON that omits a closing ] or } causes this error at the very end of the input. The fix is to validate the file structure — use the JSONSmith validator to find the exact missing character.
Invalid
{"users": [{"name": "Alice"}, {"name": "Bob"}Valid
{"users": [{"name": "Alice"}, {"name": "Bob"}]}Unterminated string literal near the end of the file
A string that was opened with a double quote but never closed causes the parser to consume the rest of the input looking for the closing quote, ultimately reaching the end. Often seen when JSON is written by string concatenation rather than serialization.
Invalid
{"message": "Hello world}Valid
{"message": "Hello world"}Fix this error in seconds
Paste your JSON in the free validator to find the exact line and column where the error occurs.
Open JSON Validator →Frequently Asked Questions
Can this error be caused by a comment inside the JSON file?
Yes. JSON does not support comments. If you have // or /* */ comments in a .json file (common in tsconfig.json or jest.config.json, which use JSONC), and you parse it with standard JSON.parse, the parser will choke on the comment characters. Use a JSONC-aware parser or strip comments first.
How is this different from ‘Unexpected token < in JSON’?
"Unexpected end of JSON input" means the input ran out before a valid structure was complete, while "Unexpected token <" means the input starts with the wrong character entirely (usually an HTML page). Both indicate the input is not JSON, but the root causes differ: truncation vs. receiving the wrong content type.