How to Read JSON from a File in Python with json.load
Settings, saved results and the answers of web APIs are often JSON. json.load reads it from an open file, or anything that behaves like one, and gives you ordinary Python values: a dictionary for each JSON object and a list for each array. This guide reads a small JSON file on Python 3.15.2.
Syntax
import json
with open("<file>.json", encoding="utf-8") as file:
<data> = json.load(file)
| Part | What it means |
|---|---|
open("<file>.json", encoding="utf-8") | Opens the file for reading as text. JSON files are UTF-8 |
json.load(file) | Reads the whole file and turns the JSON into Python values |
<data> | The result: a dict for a JSON object, a list for an array |
Python's json documentation describes its argument as "A .read()-supporting text file or binary file containing the JSON document to be deserialized."
The Example
A file named book.json describes a book. The script reads it, prints the result, uses two of its values, and shows that the JSON array came back as a Python list.
Prerequisites
- uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Create the JSON File
{"title": "The Hobbit", "year": 1937, "tags": ["fantasy", "adventure"]}
Step 2: Write the Script
import json
with open("book.json", encoding="utf-8") as file:
book = json.load(file)
print(book)
print(book["title"], book["year"])
print(type(book["tags"]).__name__)

Step 3: Run It
uv run python json_load_demo.py
{'title': 'The Hobbit', 'year': 1937, 'tags': ['fantasy', 'adventure']}
The Hobbit 1937
list

The JSON object became a dictionary, so book["title"] reads the title. The number stayed a number (1937, without quotes), and the array became a list. The command works unchanged in PowerShell.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Passing JSON text to json.load: json.load('{"title": "The Hobbit"}') | AttributeError: 'str' object has no attribute 'read', because load calls .read() on what you give it | Use json.loads for text |
Leaving out encoding="utf-8" | Fine on Python 3.15, where "Python now uses UTF-8 as the default encoding" (What's New in 3.15). Older versions use the system's locale encoding, which can garble accented letters on Windows | Pass encoding="utf-8", so the code reads the file the same way on every version |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
AttributeError: 'str' object has no attribute 'read' | The argument is text, not a file | json.loads(text) |
KeyError: 'title' | The JSON has no such key, or it's spelled differently | Print the dictionary first and check the key |
FAQ
What's the difference between json.load and json.loads?
load reads from a file. loads reads from text: the documentation calls it "Identical to load(), but instead of a file-like object", deserializing a string. json.loads('{"title": "The Hobbit"}') returns {'title': 'The Hobbit'}.
Can json.load read a web response?
Yes, if the response has a .read() method, as the object urllib.request.urlopen returns does: json.load(response).
Conclusion
json.load(file) turned book.json into a dictionary whose title, year and list of tags were ready to use. Use json.load for files and file-like objects, and json.loads for text.
Additional Resources
- json.load — its options.
- JSON-to-Python conversion table — which JSON type becomes which Python type.
