SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data means the parser successfully read one complete JSON value — and then found more non-whitespace content after it. JSON allows exactly one top-level value, so anything trailing it is an error. Here's what causes the "extra data" and how to fix it.
What the Error Looks Like
// Firefox
SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data
at line 1 column 18 of the JSON data
// V8 (Chrome / Node / Edge)
SyntaxError: Unexpected non-whitespace character after JSON at position 17
SyntaxError: Unexpected token { in JSON at position 17 // older wording
// Python (analogous)
json.decoder.JSONDecodeError: Extra data: line 1 column 18 (char 17)The position points to the first character after the valid value — that's where the "extra" begins.
Why It Happens
Cause 1 — Two JSON values concatenated
// ❌ two objects back-to-back — valid value, then more
{"id":1}{"id":2}
// ^ position 8: unexpected non-whitespace after JSON data
// ✅ wrap them in an array
[{"id":1},{"id":2}]Cause 2 — NDJSON / JSON Lines parsed as one blob
Log files and streaming APIs often emit one JSON object per line (NDJSON). JSON.parse() only reads the first line's value, then trips on the next.
// ❌ JSON.parse on the whole file
{"event":"login"}
{"event":"logout"}
// ✅ parse line by line
const rows = text
.split('\n')
.filter(Boolean)
.map((line) => JSON.parse(line));Cause 3 — Trailing junk or a doubled response
// ❌ stray text, BOM-less duplicate, or a trailing semicolon
{"ok":true};
{"ok":true} // extra debug line appended by a proxy
extraJSON-RPC and Other Framed Streams
If you're consuming a protocol — JSON-RPC over stdio, the Language Server Protocol (LSP), the Debug Adapter Protocol — multiple JSON messages flow over one channel by design. They each carry a framing layer that says how long the next message is, exactly so you don't end up trying to parse two values in one buffer:
Content-Length: 87\r\n
\r\n
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{...}}Content-Length: 42\r\n
\r\n
{"jsonrpc":"2.0","id":1,"result":{...}} The rule: read the Content-Length header, then read exactly that many bytes, then parse one JSON value, then loop. If you slurp the whole channel and parse it once, you'll hit "unexpected non-whitespace character after JSON data" because there are many values in there.
For NDJSON the equivalent rule is "split on \n, parse each line." The common thread: a stream of JSON messages always needs a framing layer; raw concatenation isn't legal JSON.
How to Fix It — Step by Step
- Go to the reported position — everything from there on is the "extra data." Inspect what immediately follows the first complete value.
- Multiple values? If you meant a list, wrap them in a
[ … ]array separated by commas. - NDJSON / JSON Lines? Split on newlines and parse each line separately — don't parse the whole file at once.
- Trailing junk? Trim the stray characters (a semicolon, a duplicated payload, debug output) before parsing.
- Streaming? Make sure you're not concatenating multiple responses into one buffer before parsing.
Frequently Asked Questions
What does "unexpected non-whitespace character after JSON data" mean?
The parser read one valid JSON value and then found more content after it. JSON permits only a single top-level value, so the trailing characters are invalid.
How do I parse multiple JSON objects?
If they're concatenated, wrap them in an array. If they're one-per-line (NDJSON / JSON Lines), split on the newline and JSON.parse() each line individually.
Is this the same as "Unexpected end of JSON input"?
They're opposites. This error means there's too much data (extra after a complete value); "Unexpected end of JSON input" means there's too little (the value was cut off).
Fix It Now
- JSON Fix — spot the trailing data and clean it up in your browser
- Unexpected End of JSON Input — the opposite "too little data" error
- How to Fix JSON.parse "Unexpected Token" Errors — every token variant
- Fix "[object Object] is not valid JSON" — the complete syntax-error reference