Read and write JSON data.
The json module converts between JSON text and Python objects.
json.loads(text): JSON string → Python (dict, list…).
json.dumps(obj): Python → JSON string.
indent=2 pretty-prints; sort_keys=True sorts keys.
json.load(file) and json.dump(obj, file) work with files.
Mapping: dict ↔ object, list ↔ array, str ↔ string, True/False ↔ true/false, None ↔ null.
💡 Key Takeaways: Python JSON
Mastering Python JSON helps you write clean and reliable Python code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
Python JSON Code Example
Python
import json
text = '{"name": "Sara", "courses": ["Python", "SQL"], "active": true, "manager": null}'
data = json.loads(text)
print(data["name"], data["courses"], data["active"], data["manager"])
data["courses"].append("Django")
print(json.dumps(data, indent=2))
Free sign-in required · Google login available
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services