Load JSON in Python: Easy Example Tutorial

Logan Jul 13, 2026

JSON, or JavaScript Object Notation, is a lightweight data interchange format that's easy for humans to read and write, and easy for machines to parse and generate. In Python, we can use the json library to work with JSON data. Let's explore how to load JSON data using Python.

json.loads vs json.dumps in Python
json.loads vs json.dumps in Python

Before we dive in, make sure you have JSON data ready. Here's an example JSON file named `data.json`:

All Important Python Functions for Beginners (Complete Cheat Sheet)
All Important Python Functions for Beginners (Complete Cheat Sheet)

```json { "name": "John", "age": 30, "city": "New York" } ```

Using json.load()

json.load() is used when loading data from a file or file-like object. It reads the entire file at once and returns the decoded JSON object.

Python Read JSON File – How to Load JSON from a File and Parse Dumps
Python Read JSON File – How to Load JSON from a File and Parse Dumps

Here's a Python script that reads `data.json` and loads the JSON data:

```python import json # Open the JSON file with open('data.json', 'r') as f: data = json.load(f) print(data) ```

Output:

a computer screen with the words python string method
a computer screen with the words python string method

```python {'name': 'John', 'age': 30, 'city': 'New York'} ```

Handling Large Files

If you're dealing with large JSON files, you might want to consider using json.load() with the `fileobj` function from `io` library, which allows reading in chunks.

Here's an example:

Python Cheat Sheet for Beginners
Python Cheat Sheet for Beginners

```python from io import BytesIO import json json_str = '''{"name": "John", "age": 30, "city": "New York"}''' # Create a file-like object from a string json_file = BytesIO(str.encode(json_str)) # Load the JSON data in chunks for chunk in json_file: data = json.loads(chunk) print(data) ```

Output:

```python {'name': 'John'} {'age': 30} {'city': 'New York'} ```

Using json.loads()

json.loads() is used to parse a JSON string and return the decoded JSON object. It's particularly useful when you have JSON data as a string.

three different types of python programming
three different types of python programming

Here's an example:

```python import json json_str = '{"name": "John", "age": 30, "city": "New York"}' # Load JSON data from string data = json.loads(json_str) print(data) ```

Output:

the top 50 python project ideas
the top 50 python project ideas
Python Lists in Python Programming
Python Lists in Python Programming
Python Remove Substring with Examples
Python Remove Substring with Examples
Loops in Python 💻
Loops in Python 💻
9 Python Projects for Beginners (Build Your Portfolio Fast)
9 Python Projects for Beginners (Build Your Portfolio Fast)
Python Errors and Exception Handling | Codevisionz
Python Errors and Exception Handling | Codevisionz
Ultimate Python Cheat Sheet for Beginner
Ultimate Python Cheat Sheet for Beginner
the different types of logos are shown in this diagram, and there is also an info sheet
the different types of logos are shown in this diagram, and there is also an info sheet
How to Print Exception in Python with Examples
How to Print Exception in Python with Examples
Python Programming, Python
Python Programming, Python
While loop in Python Easy to learn 🤩
While loop in Python Easy to learn 🤩
Python List Methods
Python List Methods
How To Iterate Through A List In Python, Choosing The Right Python Ide, Python List Methods Examples, Python List Methods Infographic, How To Implement One-to-many In Python, How To Use List Methods In Python, Best Ide For Python Development, Python List, Python Project Ideas List
How To Iterate Through A List In Python, Choosing The Right Python Ide, Python List Methods Examples, Python List Methods Infographic, How To Implement One-to-many In Python, How To Use List Methods In Python, Best Ide For Python Development, Python List, Python Project Ideas List
Goldmine Uncovered! Elite Python, Java, JS Help: Search No More – Dive into Premium Coding Now!
Goldmine Uncovered! Elite Python, Java, JS Help: Search No More – Dive into Premium Coding Now!
API Error Handling in Python: Complete Guide with Code Examples
API Error Handling in Python: Complete Guide with Code Examples
Python For Everything – Top Libraries & What They’re Used For
Python For Everything – Top Libraries & What They’re Used For
an image of a cartoon character with the words python print versus logging
an image of a cartoon character with the words python print versus logging
Python Coding Practice | Easy Programming Logic
Python Coding Practice | Easy Programming Logic
100 Python Project for beginners, intermediate and advanced programmers
100 Python Project for beginners, intermediate and advanced programmers

```python {'name': 'John', 'age': 30, 'city': 'New York'} ```

Handling Multiple JSON Objects

json.loads() can also handle multiple JSON objects in a single string, separated by commas.

Here's an example:

```python import json json_str = '[{"name": "John", "age": 30}, {"name": "Jane", "age": 25}]' # Load JSON data from string (a list of objects) data = json.loads(json_str) print(data) ```

Output:

```python [{'name': 'John', 'age': 30}, {'name': 'Jane', 'age': 25}] ```

And there you have it! You've seen how to load JSON data in Python using json.load() and json.loads().

To practice more, you can try loading JSON data from a URL using `requests` library, or handling nested JSON data. Happy coding!