August 10, 2026
How to Parse JSON in Python
How to Parse JSON in Python
Python provides the built-in json module to easily encode and decode JSON data.
Parsing JSON Strings
Use json.loads() (load string) to convert a JSON string into a Python dictionary.
import json
json_string = '{"name": "Alice", "age": 25, "active": true}'
user_dict = json.loads(json_string)
print(user_dict["name"]) # Output: Alice
print(user_dict["active"]) # Output: True (Note the capital T)
Generating JSON
Use json.dumps() (dump string) to convert a dictionary back to JSON.
data = {"name": "Bob", "active": False}
json_string = json.dumps(data, indent=4)
If you want to instantly convert a JSON structure into Python code, try our JSON to Python Converter.
