Unexpected Non-Whitespace Character After JSON: What It Means and How to Fix It
JSON.parse finished reading one complete value, then found more text where the input was supposed to end. That is the whole meaning of “unexpected non-whitespace character after JSON.” And unlike most parse errors, the position number in the message points at exactly where the extra text begins.
{"id":1}{"id":2}. Paste that into a console and JSON.parse dies at position 9. Each object parses cleanly on its own; together they are two documents, and the parser accepts exactly one. A dev.to writeup from a few weeks back used this exact minimal case: two objects copied out of an AI chat response, pasted into one buffer, no separator between them. Nothing inside either object needs fixing. The broken assumption is that they form a single document.
That is what the message is telling you, in unusually plain language for a parser. The JSON grammar allows one top-level value followed by nothing but whitespace. So a “non-whitespace character after JSON” means the parser completed a value and the next meaningful character had no business being there. This makes the reported position honest, which is rare. With a missing comma, the parser blames the line where it gave up, usually one line below the actual mistake (I wrote about that here). With this error, the position names the first character of the extra text. Start there.
Other tools report the same failure under different names. Python’s json.loads says “Extra data: line 1 column N.” VS Code’s JSON language support says “End of file expected.” The cause and the fix are identical; only the wording changes.
How to fix “unexpected non-whitespace character after JSON,” case by case
The fix depends on what the extra text is. There are four usual suspects, and they want different treatment.
Two values pasted side by side. Two API responses concatenated into one buffer, two code blocks from documentation merged into one string. If the values belong together as one collection, wrap them in an array and separate them with commas:
{"id":1}{"id":2}
[{"id":1},{"id":2}]
Note the trap: inserting only a comma, {"id":1},{"id":2}, does not fix anything. A bare comma is illegal at the top level of JSON; commas only separate items inside an array or object. You need the brackets.
JSON Lines content parsed as one document. NDJSON and .jsonl files put one complete JSON value per line, and the whole file is not a single JSON document (more on that format here). Split the text into lines and parse each one:
const records = raw .split(/\r?\n/) .filter(line => line.trim()) .map(line => JSON.parse(line));
This only works when each line really holds one complete value. If the objects are pretty-printed across multiple lines, line-splitting shreds them, and you need a streaming parser instead.
Trailing prose after the JSON. A log line appended after the payload, an AI reply that adds “hope this helps!” below the code block, a stray word like done after the closing brace. Cut the text at the position the error names and parse the head. The position does the diagnosis for you: whatever starts there is the intruder.
Two pretty-printed objects stacked with blank lines between them. Same treatment as the first case: they are two documents that want to be one array.
Here is where I will plant a flag. This error is a data-shape decision, not a syntax bug, which is why I am skeptical of repair tools that “fix” it silently. Wrapping in an array and splitting into records are opposite meanings: one says these values belong together, the other says they are separate events. A tool that picks for you is guessing about your data. The honest behavior is to show both readings and let you choose. When you paste this error into the JSON Repair Tool, that is the question it should be answering, not just the syntax.
In Python the same input raises json.decoder.JSONDecodeError: Extra data. The treatment does not change: wrap, split, or trim, depending on which of the four cases you are in.
Next time it fires, look at the character sitting at the reported position. That character is the start of the second document, and naming it tells you the case within seconds: a { or [ means concatenated values, a letter means trailing prose, a stack of newline-separated objects means JSON Lines. Diagnose the character, then apply the matching fix.
Pasted JSON that looks fine but won't parse?
Drop it in. We strip BOMs, smart quotes, and control characters, and show you what changed.
Repair My JSON FreeFrequently asked questions
What does the position number in this error actually point to?
The first character after the completed JSON value (the start of the extra text). Unlike most parse errors, this position is accurate, so look there first instead of scanning the whole document.
Python says “Extra data” instead. Is it the same problem?
Yes. Python’s json.loads reports “Extra data: line L column C” for exactly this input. The fix is the same: wrap the values in an array, split them into lines, or trim the trailing text.
Why doesn’t adding a comma between the two objects fix it?
A comma at the top level is not legal JSON. Commas only separate items inside an array or object, so {"id":1},{"id":2} is still two documents. You need the surrounding square brackets.
My input is a .jsonl file. How should I parse it?
Split on newlines, drop blank lines, and parse each line separately. That works only when each line holds one complete value; pretty-printed objects spanning multiple lines need a streaming parser.
Related reading: NDJSON Broke My Parser: How to Fix JSON Lines Errors · “Unexpected End of JSON Input”: Empty Body, Cut-Off Payload, or Unclosed Bracket · Why Is My JSON Invalid? The 7 Syntax Errors That Break JSON.parse
One JSON gotcha a week, no fluff: Subscribe to the newsletter.