Extra data: two JSON documents where one was expected
By Santhi · Messages captured October 9, 2026 on 11 runtimes · How we test
The parser read one complete JSON value and then found more text after it. JSON.parse and json.loads accept exactly one value. The usual reason is a JSON Lines file (also called NDJSON), where each line is its own document.
What each runtime prints
We ran this input through JSON.parse in each browser and Node version, and through json.loads in Python. These are the messages exactly as printed.
{"a": 1}
{"b": 2}| Runtime | Exact message |
|---|---|
| Chrome 151Node 24Node 22 | Unexpected non-whitespace character after JSON at position 9 (line 2 column 1) |
| Firefox 153 | JSON.parse: unexpected non-whitespace character after JSON data at line 2 column 1 of the JSON data |
| Safari 26 (WebKit)Bun | JSON Parse error: Unable to parse JSON string |
| Node 20 | Unexpected non-whitespace character after JSON at position 9 |
| Node 18 | Unexpected token { in JSON at position 9 |
| Python 3.13Python 3.12Python 3.10 | JSONDecodeError: Extra data: line 2 column 1 (char 9) |
- Chrome, Node 20+, Firefox and Python all point at line 2, column 1: the start of the second document.
- Safari says only "Unable to parse JSON string", with no position.
- Node 18 says "Unexpected token { in JSON at position 9". The { is the start of the second object.
Edit it or paste your own. It runs in your browser; nothing is uploaded.
Common causes
- 1
A JSON Lines file
Log files, event exports, and batch files for many AI and data APIs use one JSON object per line, often with the extension .jsonl or .ndjson.
- 2
json.dump() called more than once on the same file
Appending a new object to a file in a loop writes several documents side by side, not one list.
- 3
Two responses or chunks joined together
Reading a streaming response and concatenating the chunks, or a retry that appended a second body to the first.
How to fix it
If the data is JSON Lines, parse each line on its own.
JavaScript
const rows = text
.split('\n')
.filter((line) => line.trim())
.map((line) => JSON.parse(line));Python
import json
with open("events.jsonl", encoding="utf-8") as f:
rows = [json.loads(line) for line in f if line.strip()]- If the documents are joined with no newline between them, Python can still split them: json.JSONDecoder().raw_decode(text, i) returns one value and the index where it ends, so you can loop until the end of the text.
- If you write the file yourself and want one document, collect the objects in a list and call json.dump() once.