Sponsored Reserved space — layout preview until AdSense is connected

Reference library

Python code samples

Medium snippets you can copy, study, and run in the browser editor.

1 match
Sponsored Reserved space — layout preview until AdSense is connected
Files & data medium

Parse JSON safely

Load JSON from a string and handle decode errors without crashing.

json parsing stdlib
Python
import json

payload = '{"name": "Ada", "skills": ["Python", "math"]}'

try:
    data = json.loads(payload)
    print(data["name"])
    print(", ".join(data["skills"]))
except json.JSONDecodeError as exc:
    print(f"Invalid JSON: {exc}")
3 0 Open

Browse by section

Each section groups closely related Python snippets.