TL;DR: To parse JSON in Python, use the built-in json module: json.loads() for a string or bytes, json.load() for a file, and Requests' response.json() for an HTTP response. Check the HTTP status and JSON validity separately, because a 200 response can still be HTML. This guide also covers decode errors, nested access, validation, large files, and JSON hidden inside web pages.
Python's built-in json module parses JSON. Use json.loads() for a string or bytes, json.load() for a file, and Requests' response.json() for an HTTP response. This guide covers decode errors, safe nested access, validation, large files, number precision, and JSON hidden inside web pages.
Key takeaways
- Prefer
json.loadsfor strings/bytes andjson.loadfor files; open files with UTF-8 (orutf-8-sigwhen a BOM is present). - Treat HTTP status and JSON validity as separate checks: a 200 response can still be HTML.
- Navigate messy nested data with
.get()chains or a smalldig()helper; validate with Pydantic or JSON Schema after parsing. - Stream huge arrays with ijson, append scrape runs as JSON Lines, and measure orjson on your own payloads.
- Prefer JSON embedded in the page (JSON-LD,
__NEXT_DATA__) or a scraping API's structured fields over brittle CSS selectors when the HTML layout changes often.




