To load a JSON file in Python, use the json.load() method from the built-in json module. This method reads a file object and parses the JSON content into a Python object (typically a dictionary or list).

Basic Usage

import json

with open('data.json', 'r') as file:
    data = json.load(file)

print(data)
  • json.load() is used for files.

  • json.loads() is used for JSON strings.

Key Points

  • Always open the file in read mode ('r').

  • Use the with statement to ensure the file is properly closed after reading.

  • Handle potential errors like FileNotFoundError or json.JSONDecodeError for robust code.

Example with Error Handling

import json

try:
    with open('config.json', 'r') as file:
        config = json.load(file)
    print("Config loaded:", config)
except FileNotFoundError:
    print("Config file not found.")
except json.JSONDecodeError:
    print("Invalid JSON format in file.")

Loading Nested or Complex Data

with open('complex_data.json', 'r') as file:
    data = json.load(file)

# Access nested values
user_name = data['user']['name']
print(user_name)

For prettier output when writing JSON, use the indent parameter with json.dump().

The json.load() method (without "s" in "load") can read a file directly:

import json

with open('strings.json') as f:
    d = json.load(f)
    print(d)

You were using the json.loads() method, which is used for string arguments only.


The error you get with json.loads is a totally different problem. In that case, there is some invalid JSON content in that file. For that, I would recommend running the file through a JSON validator.

There are also solutions for fixing JSON like for example How do I automatically fix an invalid JSON string?.

Answer from ubomb on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › read-json-file-using-python
Read JSON file using Python - GeeksforGeeks
... import json try: with open('data.json', 'r') as file: data = json.load(file) print("File data =", data) except FileNotFoundError: print("Error: The file 'data.json' was not found.")
Published   September 15, 2025
Discussions

python - Loading and parsing a JSON file with multiple JSON objects - Stack Overflow
I am trying to load and parse a JSON file in Python. But I'm stuck trying to load the file: import json json_data = open('file') data = json.load(json_data) Yields: ValueError: Extra data: line 2 More on stackoverflow.com
🌐 stackoverflow.com
How do I open or even find a json file?
You store python objects in a file and retrieve the objects from a file using the json module. This tutorial shows you the basics, and you can search for other tutorials. The python doc is here . More on reddit.com
🌐 r/learnpython
23
0
June 26, 2024
On read of JSON file it loads the entire JSON into memory.
You can't really, given that structure. Because you have the surrounding list/array, the parser can't output anything until it finds the end of that array, which is at the end of the file. You might consider using json-lines format (also known as newline-delimited JSON ), in which each line is a separate JSON document so they can be loaded individually. More on reddit.com
🌐 r/learnpython
7
2
July 19, 2022
Handling JSON files with ease in Python
Looks good. Considered discussing dataclasses/pydantic with json? I found that these go well together More on reddit.com
🌐 r/Python
55
421
May 29, 2022
🌐
Imperial College London
python.pages.doc.ic.ac.uk › java › lessons › java › 10-files › 03-load.html
Python for Java Programmers > Loading JSON files
The json module allows you to easily load a JSON file into its equivalent Python object (usually a dict or list). To load your data from a JSON file, use json.load(file_object).
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - How can you read JSON data from a file into a Python program?Show/Hide · You can use the json.load() function to deserialize JSON data from a file into a Python object.
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
Python has a built-in package called json, which can be used to work with JSON data. ... If you have a JSON string, you can parse it by using the json.loads() method.
🌐
Medium
medium.com › @ryan_forrester_ › save-and-load-json-files-in-python-a-complete-guide-49a5760b8b49
Save and Load JSON Files in Python: A Complete Guide | by ryan | Medium
October 28, 2024 - - `open()` creates a file in write mode (“w”) - `json.dump()` writes the data directly to the file - The `with` statement ensures the file closes properly - Python handles the JSON conversion automatically ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › json-load-in-python
json.load() in Python - GeeksforGeeks
August 11, 2025 - import json # Opening and reading the JSON file with open('data.json', 'r') as f: # Parsing the JSON file into a Python dictionary data = json.load(f) # Iterating over employee details for emp in data['emp_details']: print(emp)
🌐
NetworkAcademy
networkacademy.io › learning path: ccna automation (200-901) ccnaauto › data formats and data models › parsing json with python
Parsing JSON with Python | NetworkAcademy.IO
Usually, in real life, you are not going to need to parse JSON from within a python script. You will need to parse it from an external json file. So let's look at the following example. with open('example.json') as f: data = json.load(f)
🌐
Python
docs.python.org › 3 › library › json.html
JSON encoder and decoder — Python 3.14.3 documentation
3 weeks ago - fp can now be a binary file. The input encoding should be UTF-8, UTF-16 or UTF-32. Changed in version 3.11: The default parse_int of int() now limits the maximum length of the integer string via the interpreter’s integer string conversion length limitation to help avoid denial of service attacks. json.loads(s, *, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)¶
🌐
Zyte
zyte.com › home › blog › json parsing with python [practical guide]
A Practical Guide to JSON Parsing with Python
July 6, 2023 - We load the data using the with open() context manager and json.load() to load the contents of the JSON file into a Python dictionary.
🌐
freeCodeCamp
freecodecamp.org › news › loading-a-json-file-in-python-how-to-read-and-parse-json
Loading a JSON File in Python – How to Read and Parse JSON
July 25, 2022 - This is because null is not valid in Python. The json module also has the load method which you can use to read a file object and parse it at the same time. Using this method, you can update the previous code to this: import json with open('user.json') as user_file: parsed_json = json.load(user_file) print(parsed_json) # { # 'name': 'John', # 'age': 50, # 'is_married': False, # 'profession': None, # 'hobbies': ['travelling', 'photography'] # }
🌐
GeeksforGeeks
geeksforgeeks.org › python › reading-and-writing-json-to-a-file-in-python
Reading and Writing JSON to a File in Python - GeeksforGeeks
This process is called deserialization. Python offers two main ways to read JSON data: The JSON package has json.load() function that loads the JSON content from a JSON file into a dictionary.
Published   August 5, 2025
🌐
Dive into Python
diveintopython.org › home › learn python programming › file handling and file operations › operations with json files
JSON with Python - Read, Write, Print and Parse JSON Files with Examples
May 3, 2024 - This example shows how to open JSON file in Python and work with it. The json module in Python offers various functions to handle JSON data efficiently. json.load(): This function loads JSON data from a file-like object and converts it into a Python object.
🌐
LabEx
labex.io › tutorials › python-how-to-load-json-from-file-438170
How to load JSON from file | LabEx
Python provides the built-in json module for working with JSON data. To load JSON files, you'll primarily use two methods: The json.load() method reads JSON directly from a file object:
🌐
Reddit
reddit.com › r/learnpython › how do i open or even find a json file?
r/learnpython on Reddit: How do I open or even find a json file?
June 26, 2024 -

I'm making a text based rpg in python and i learnt that the data can be saved to a json file and then can be read from it and used. But how do I access that json file? Or maybe i should do another method to save game? Also is there a way to open a json file in python so that python can read it's values?

🌐
Leapcell
leapcell.io › blog › how-to-read-json-in-python
How to Read JSON in Python | Leapcell
July 25, 2025 - Use json.loads() to parse JSON strings into Python objects. Use json.load() to read JSON data from a file.
🌐
W3Schools
w3schools.com › python › pandas › pandas_json.asp
Pandas Read JSON
In our examples we will be using a JSON file called 'data.json'. Open data.json. ... Tip: use to_string() to print the entire DataFrame. ... JSON objects have the same format as Python dictionaries.