JSON Errors / Python

json.decoder.JSONDecodeError: Extra data

How to Fix: json.decoder.JSONDecodeError: Extra data

json.loads() successfully parsed one complete JSON value - and then found more content after it. A JSON document may contain exactly one top-level value, so {"a":1}{"b":2} or two lines of objects is invalid as a single document.

The error position tells you where the first value ended. Content there means you have multiple JSON documents in one string: usually JSON Lines (one object per line, common in logs and data exports) or accidentally concatenated API responses.

{"find": "error"}paste your JSON below

Common causes

1. JSON Lines (JSONL/NDJSON) file parsed as one document

Log files and dataset exports often store one JSON object per line. json.load() on the whole file fails as soon as line 2 begins.

Invalid
{"event": "login", "user": 1}
{"event": "logout", "user": 1}

2. Concatenated JSON documents

Appending JSON blobs to the same file or buffer without a wrapping array produces {"a":1}{"b":2} - two documents back to back.

3. Trailing garbage after valid JSON

A stray character, a duplicated closing brace from manual editing, or log prefixes/suffixes around the JSON payload.

How to fix it

Parse JSON Lines correctly (Python)
import json

records = []
with open("events.jsonl") as f:
    for line in f:
        line = line.strip()
        if line:
            records.append(json.loads(line))
Parse concatenated JSON with raw_decode (Python)
import json

decoder = json.JSONDecoder()
text = '{"a": 1}{"b": 2}'
values, idx = [], 0
while idx < len(text):
    value, end = decoder.raw_decode(text, idx)
    values.append(value)
    idx = end
    while idx < len(text) and text[idx].isspace():
        idx += 1

Frequently asked questions

How do I tell if my file is JSON or JSON Lines?

Open it and look at the top-level structure: a JSON file has one value (usually starting with [ or {) spanning the whole file; JSON Lines has a complete object on every line with no enclosing array and no commas between lines. File extensions .jsonl or .ndjson are also a giveaway.

Why is JSON Lines even used if it is not valid JSON?

It is streamable and appendable: you can process records one line at a time without loading the whole file, and appending a record never requires rewriting the document. That makes it standard for logs, exports, and ML datasets.

Can pandas read JSON Lines directly?

Yes - pd.read_json('file.jsonl', lines=True) parses one object per line into a DataFrame, which is usually the fastest route for tabular JSONL data.

Last updated:

Related JSON errors

You might also need

Free and in-browser, like everything on JSON Console. Browse all tools →