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 in Python is a breeze thanks to the built-in json module. In this guide, we'll cover the basics of reading and writing JSON data.

Reading JSON Data

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

Alternatively, you can use json.loads() to parse a JSON string.


python
import json

json_string = '{"name": "John", "age": 30}'
data = json.loads

---

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

---

*🛠️ Useful resource: **Content Creator Ultimate Bundle (Save 33%)** — $29.99. Check it out on Gumroad!*
Enter fullscreen mode Exit fullscreen mode

Top comments (0)