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

In this guide, we will cover the basics of reading and writing JSON data in Python using the built-in json module.

Reading JSON

To read JSON data from a file, use json.load(). This function takes a file object as an argument and returns a Python dictionary.

import json

with open('data.json') as f:
    data = json.load(f)
Enter fullscreen mode Exit fullscreen mode

To parse a JSON string, use json.loads().

import json

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

Writing JSON

To write JSON data


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


💡 Related: **Content Creator Ultimate Bundle (Save 33%)* — $29.99*

Top comments (0)