Extra data: line L column C (char N)
json.loads parsed a complete value and then found more content. Python calls that extra data. If the reported line is 2 or later and each line looks like a complete record, the file is JSON Lines and needs to be read one line at a time.
Paste your JSON and see exactly where it breaks
Nothing you paste leaves your browser. The connect-src allowlist makes that a browser guarantee rather than a promise. Check it yourself
What actually causes it
Ranked by how often each one turns out to be the answer.
-
01 The file is JSON Lines
One JSON object per line, no commas, no wrapping array. Standard output format for logs, BigQuery exports and streaming APIs.
Breaks
with open('events.jsonl') as f: data = json.load(f) # Extra data: line 2 column 1Works
with open('events.jsonl') as f: data = [json.loads(line) for line in f if line.strip()] # or, with pandas import pandas as pd df = pd.read_json('events.jsonl', lines=True) -
02 json.dumps was called in a loop, appending to one file
Each call writes a complete document, so the file ends up holding several. Either write JSON Lines deliberately and read it as such, or collect the records into a list and dump once.
Breaks
for row in rows: f.write(json.dumps(row))Works
for row in rows: f.write(json.dumps(row) + '\n') # NDJSON, read line by line # or f.write(json.dumps(rows)) # one array -
03 Two responses concatenated
A retry appended to a buffer rather than replacing it.
The same mistake in other runtimes
The underlying problem is identical; only the wording differs. If a colleague reports one of these, they are looking at the same thing you are.
| JavaScript (V8) | Unexpected non-whitespace character after JSON at position 8 (line 2 column 1) |
|---|
Questions
- Is there a Python function that reads several documents from one string?
- json.JSONDecoder().raw_decode(s, idx) parses one value and tells you where it stopped, so you can loop. For line-delimited files, splitting on newlines is simpler and much faster.
- Why does the char offset not match my line and column?
- char is the absolute index into the string, while line and column are the human-readable position. They describe the same point.
Fix it now
Paste the payload into the tool above, or go straight to the one built for this job.
Convert JSON Lines to an array