json.load() Function Explained

json.load() reads JSON data from an open file and converts it into normal Python data.

Use it when your JSON is stored in a file, not in a Python string. This is a common way to load configuration files, saved data, or exported API responses.

Quick answer

import json

with open("data.json", "r", encoding="utf-8") as file:
    data = json.load(file)

print(data)
print(type(data))

Use json.load() when you already have an open file object. It converts JSON from the file into Python data like dict, list, str, int, float, bool, or None.

What json.load() does

json.load():

  • Reads JSON content from a file object
  • Parses the JSON text into Python data
  • Usually returns a dictionary or list
  • Belongs to Python’s built-in json module

Before using it, import the module:

import json

If you want a broader introduction first, see the Python json module overview.

Basic syntax

The basic syntax is:

json.load(file_object)

Important points:

  • Import the module first with import json
  • Open the file before calling json.load()
  • Pass the file variable, not the file name string

Correct:

import json

with open("data.json", "r", encoding="utf-8") as file:
    data = json.load(file)

Incorrect:

import json

data = json.load("data.json")

The second example fails because "data.json" is a string path, not an open file object.

If you need help opening files, see how to read a file in Python.

What json.load() returns

json.load() returns the Python type that matches the JSON content.

Here is the usual conversion:

  • JSON object → Python dict
  • JSON array → Python list
  • JSON string → Python str
  • JSON number → Python int or float
  • JSON true and false → Python True and False
  • JSON null → Python None

Example JSON file:

{
  "name": "Maya",
  "age": 25,
  "is_admin": false,
  "skills": ["Python", "SQL"],
  "manager": null
}

Python code:

import json

with open("data.json", "r", encoding="utf-8") as file:
    data = json.load(file)

print(data)
print(type(data))
print(data["name"])
print(type(data["skills"]))

Expected output:

{'name': 'Maya', 'age': 25, 'is_admin': False, 'skills': ['Python', 'SQL'], 'manager': None}
<class 'dict'>
Maya
<class 'list'>

Step-by-step example

Let’s go through a full example.

1. Create a JSON file

Create a file named data.json:

{
  "title": "Python Basics",
  "pages": 120,
  "available": true
}

2. Open the file in read mode

Use open() with "r" mode:

file = open("data.json", "r", encoding="utf-8")

3. Call json.load(file)

This reads and parses the JSON:

data = json.load(file)

4. Store the result in a variable

Now data contains Python data you can use in your program.

5. Access values like normal Python data

Full example:

import json

with open("data.json", "r", encoding="utf-8") as file:
    data = json.load(file)

print(data)
print(data["title"])
print(data["pages"])
print(data["available"])

Expected output:

{'title': 'Python Basics', 'pages': 120, 'available': True}
Python Basics
120
True

Key line:

data = json.load(file)

This is the line that turns JSON text from the file into a Python dictionary.

If you want a more task-focused guide, see how to parse JSON in Python.

json.load() vs json.loads()

These two functions are similar, but they do not take the same kind of input.

Use json.load() for files

json.load() reads JSON from a file object:

import json

with open("data.json", "r", encoding="utf-8") as file:
    data = json.load(file)

Use json.loads() for strings

json.loads() reads JSON from a string:

import json

text = '{"name": "Liam", "age": 30}'
data = json.loads(text)

print(data)

Expected output:

{'name': 'Liam', 'age': 30}

In short:

  • Use load for files
  • Use loads for JSON text already stored in a variable

For more detail, see json.loads() function explained.

Common errors beginners make

Here are some common problems when using json.load().

Passing a file path string instead of an open file

This is wrong:

import json

data = json.load("data.json")

Why it fails:

  • json.load() expects a file object
  • "data.json" is only a string

Fix:

import json

with open("data.json", "r", encoding="utf-8") as file:
    data = json.load(file)

Trying to load invalid JSON

JSON has strict syntax rules.

This is invalid JSON:

{
  'name': 'Ava'
}

Why it fails:

  • JSON uses double quotes, not single quotes

Correct JSON:

{
  "name": "Ava"
}

Forgetting JSON uses true, false, and null

Inside a JSON file, use:

  • true
  • false
  • null

Not:

  • True
  • False
  • None

Example valid JSON:

{
  "active": true,
  "notes": null
}

Opening the wrong file or wrong path

If Python cannot find the file, you may get a FileNotFoundError.

Example:

import json

with open("missing.json", "r", encoding="utf-8") as file:
    data = json.load(file)

If that happens, see FileNotFoundError in Python: causes and fixes.

When to use json.load()

json.load() is useful when you need to read structured data from a file.

Common use cases:

  • Reading configuration files
  • Loading saved app data
  • Working with exported API data stored in a file
  • Reading structured data for scripts

If you want to save Python data back to a file, the matching function is json.dump().

Common causes of errors

When json.load() fails, these are common causes:

  • TypeError because a string path was passed instead of a file object
  • JSONDecodeError because the JSON file has invalid syntax
  • FileNotFoundError because the file path is wrong
  • UnicodeDecodeError because the file encoding does not match the content

Helpful debugging steps:

python your_script.py
print(type(file))
print(data)
print(type(data))

These checks can help you confirm:

  • whether file is really an open file object
  • what data was loaded
  • what Python type was returned

FAQ

What is the difference between json.load() and json.loads()?

json.load() reads JSON from an open file. json.loads() reads JSON from a string.

Does json.load() always return a dictionary?

No. It returns the Python type that matches the JSON content, such as dict, list, str, int, float, bool, or None.

Can I pass a file name directly to json.load()?

No. Open the file first, then pass the file object to json.load().

Why does json.load() fail on my file?

The file may not exist, the JSON may be invalid, or the encoding may be wrong.

See also