Quick answer
json.loads() and json.load() accept exactly one JSON value. If anything other than whitespace follows it, Python raises json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 8). Fix: if the file holds one JSON object per line, parse it line by line. If the objects are joined together, wrap them in an array or read them one at a time with raw_decode. If it is a stray character, delete it.
What the message means
The numbers show where the valid JSON ended, not where the mistake is in your logic. line 2 column 1 (char 8) means the first value finished at character 7 and something else starts at character 8. Look at that exact spot in your data.
Example that fails
import json
text = '{"a": 1}\n{"b": 2}'
json.loads(text)
# json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 8)
Common causes and fixes
1. A JSON Lines (NDJSON) file
JSON Lines stores one complete JSON object on every line. The whole file is not one JSON document, so json.load(f) fails at the second line. Exports from logs, databases and many APIs use this format.
import json
items = []
with open("data.jsonl", encoding="utf-8") as f:
for line in f:
line = line.strip()
if line:
items.append(json.loads(line))
With pandas, pd.read_json("data.jsonl", lines=True) reads the same file into a table.
2. Several JSON objects joined together
Two responses saved one after the other, or objects appended to a file, give {"a": 1}{"b": 2}. That is not one JSON value. Read them one at a time with raw_decode:
import json
decoder = json.JSONDecoder()
text = text.strip()
pos = 0
items = []
while pos < len(text):
obj, end = decoder.raw_decode(text, pos)
items.append(obj)
pos = end
while pos < len(text) and text[pos].isspace():
pos += 1
Or fix the source so it writes one array, [{"a": 1}, {"b": 2}]. To combine files you already have, see Merge JSON files.
3. Stray text or an extra bracket at the end
A copy and paste that grabbed one closing brace too many, a log line added after the data, or a leftover semicolon all trigger this error.
json.loads('{"a": 1}}')
# JSONDecodeError: Extra data: line 1 column 8 (char 7)
The message points at the first character after the valid value. Delete it, or paste the text into the JSON Formatter to find mismatched brackets.
4. A file that was written twice
Opening a file in append mode ("a") and dumping a new object each run leaves several objects in one file. Open it with "w" to replace the content, or write one array.
The same error in JavaScript
- Newer Chrome and Node.js:
Unexpected non-whitespace character after JSON at position 7 - Older Chrome and Node.js:
Unexpected token { in JSON at position 7 - Firefox:
JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 8 of the JSON data
// JSON Lines in JavaScript
const items = text.trim().split("\n").map(line => JSON.parse(line));
Find the exact spot
try:
data = json.loads(text)
except json.JSONDecodeError as e:
print(e.msg, "line", e.lineno, "column", e.colno, "char", e.pos)
print(repr(text[max(0, e.pos - 20):e.pos + 20]))
Have broken JSON right now?
Paste it into the free JSON Repair tool. It runs in your browser, so nothing is uploaded.
Open JSON Repair toolFAQ
What does "Extra data" mean in JSON?
The parser read one complete JSON value and then found more text that is not whitespace. A JSON document may contain only one top-level value.
How do I read a JSON Lines file in Python?
Open the file and call json.loads() on each line, or use pandas.read_json(path, lines=True).
Is my JSON uploaded when I use Parsekit tools?
No. The tools run in your browser and nothing you paste is sent to a server.