Blog › Python · Published 2026-11-26

Why Python cannot parse your JSON: fixing json.JSONDecodeError

Python raises json.JSONDecodeError when the text is not valid JSON. The message includes the line and column of the problem.

Common causes

Debug it

import json
text = response.text
print(repr(text[:200]))
try:
    data = json.loads(text)
except json.JSONDecodeError as e:
    print(e.msg, e.lineno, e.colno)

If you hold a Python dict and want JSON text, use json.dumps(data).

Official sources

Need help with your project?
We build websites, systems and automation. Start your project WhatsApp

All articles