DEV Community

qing
qing

Posted on

2-Minute Guide: Reading and Writing JSON in Python (2026)

2-Minute Guide: Reading and Writing JSON in Python

Working with JSON data is a common task in Python development. The json module provides an easy way to read and write JSON data. Here's a quick guide to get you started:

Reading JSON

To read JSON data from a file, use json.load(). To read JSON data from a string, use json.loads().

import json

# Reading from a file
with open('data.json') as f:
    data = json.load(f)

# Reading from a string
json_string = '{"name": "John", "age": 30}'
data = json.loads(json_string)
Enter fullscreen mode Exit fullscreen mode

Writing JSON

To


Follow me on Dev.to for daily Python tips and quick guides!

Top comments (0)