JSON errors

Python, from json.loads() and json.load()

JSONDecodeError: Extra data

Python decoded one complete JSON value and then found more text after it. json.loads reads exactly one value, so a file with one object per line, or two documents back to back, stops at the start of the second.

How each browser and language words it

Python json module
json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 29)
JavaScript
SyntaxError: Unexpected non-whitespace character after JSON at position 29 (line 2 column 1)

Paste your JSON to find the exact line

One JSON object per line. Press Repair to wrap them into a single array.

Skip to editor
Explorer
Open Files

No files open

0 files open

jsoneditor.io v2

{"id": 1, "event": "signup"}
{"id": 2, "event": "login"}
{"id": 3, "event": "purchase", "total": 89.99}
JSONUTF-8
Spaces: 2

Causes and how to fix each one

1. The file is JSON Lines

Exports from BigQuery, logging tools and OpenAI batch files are JSON Lines, one JSON object per line. Read the file line by line and decode each one.

Python
import json

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

2. Several json.dump calls appended to one file

Opening a file in append mode and calling json.dump each time writes objects back to back with nothing between them. Collect the items in a list and dump once, or write one object per line on purpose and read it as JSON Lines.

3. Stray text after the JSON

A log message, a second print or a leftover bracket after the closing brace causes the same error. The column in the message points at where the extra text starts.

Questions people ask

Can json.loads read JSON Lines?

Not in one call. Split the text into lines and call json.loads on each non-empty line, or use pandas.read_json(path, lines=True) if you are loading a table.

How do I convert JSON Lines to a JSON array?

Read each line into a list and json.dump the list, or paste the lines into the JSON Lines converter on this site to get an array straight away.

Tools for this