Python JSON debugging

Python JSONDecodeError

Python raises json.JSONDecodeError when json.loads or json.load cannot decode strict JSON. The exception includes a message plus line, column and character position that can help locate malformed input.

Quick answer

Read the exception message together with line, column and char position, then inspect the surrounding input. “Expecting value” at line 1 column 1 often means the string is empty or not JSON at all.

Expecting property name enclosed in double quotes

The input often contains Python-dict syntax such as single-quoted strings or unquoted keys. Serialize Python objects with json.dumps instead of converting them with str().

Extra data

json.loads expects one JSON value. Concatenated objects or NDJSON can trigger Extra data because content remains after the first value. Parse line-delimited records individually when the source is NDJSON.

Requests and empty bodies

Calling response.json() on an empty or HTML response can raise a decode error. Inspect status_code, headers and response.text when the server behavior is uncertain.

Inspect a Python JSONDecodeError

import json

try:
    data = json.loads(text)
except json.JSONDecodeError as exc:
    print(exc.msg, exc.lineno, exc.colno, exc.pos)

Related JSON tools and guides

Frequently asked questions

What causes JSONDecodeError at line 1 column 1?

Often an empty string, whitespace-only input or a response body that is not JSON.

Can json.loads parse a Python dict string?

Only if the string also happens to be valid JSON. Python repr output commonly uses single quotes and is not valid JSON.

What does Extra data mean?

The decoder parsed one JSON value successfully but found additional non-whitespace content afterward.

Source-backed reference

JSON standards quick reference

Concise, standards-backed facts for developers working with JSON debugging and validation. Each claim is linked to the evidence registry and resolves to a primary standard or platform reference so it can be independently verified.

JSON standard
JSON is a text format for serializing structured data, with syntax defined by interoperable standards rather than by FixTools.
Strings and object keys
JSON strings and object member names use double quotation marks. Single-quoted strings are not valid standard JSON syntax.
Trailing commas
Standard JSON grammar does not allow a comma after the final member of an object or the final element of an array.
Parser behavior
JSON.parse() parses JSON text into a JavaScript value and raises a SyntaxError when the input is not valid JSON.

Common invalid → valid JSON examples

Trailing comma

{"a":1,}{"a":1}

Single-quoted key

{'a':1}{"a":1}

Unsupported literal

{"score":NaN}{"score":null}

Built for verification, not just extraction

Direct answers are paired with source-specific evidence. This keeps technical claims independently verifiable and gives search and answer systems a clearer provenance trail than unsupported summary copy.