Skip to content
JSON Tidy
JSON errors

JSONDecodeError: Extra data

The parser read one complete JSON value, reached its end, and then found more text. A JSON document is only allowed to hold a single value, so anything after it counts as “extra data”. Most often, you’re looking at a file with one JSON object per line. JavaScript reports the same thing as Unexpected non-whitespace character after JSON.

Quick fix

  1. Go to the position in the message. That’s where the second value, or the stray text, begins.
  2. If every line is its own JSON object, read the file one line at a time.
  3. If it’s supposed to be a single document, wrap the values in an array, or paste it below.

Fix your JSON

Runs in your browser. Nothing is uploaded.

A file with one JSON object per line

Log files and data exports often use JSON Lines, also called NDJSON and usually saved as .jsonl. Each line is a complete JSON value on its own, which makes the file easy to append to, but it means the file as a whole isn’t one JSON document. Read it line by line instead:

# Python
with open("events.jsonl") as f:
    events = [json.loads(line) for line in f if line.strip()]

// JavaScript
const events = text.split("\n").filter(line => line.trim()).map(line => JSON.parse(line));

If you’re using pandas, pd.read_json(path, lines=True) handles it for you.

Two documents run together

Writing to the same file twice, or joining two responses together, leaves two JSON values side by side, as in {"a": 1}{"b": 2}. The fix belongs where the file is written. Either collect the items in a list and write it once as an array, or write one value per line on purpose and read the file as JSON Lines.

Something after the closing brace

Sometimes the extra data is small. A stray } at the end, as in {"a": 1}}, triggers the same error. So does a status message a server printed after the response. Whatever follows the final closing bracket has to go.

The same error elsewhere

Pythonjson.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 29)
Chrome, Edge, Node.js 20+Unexpected non-whitespace character after JSON at position 29
FirefoxJSON.parse: unexpected non-whitespace character after JSON data
Goinvalid character '{' after top-level value
PHPjson_decode() returns null; json_last_error_msg() is "Syntax error"