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.

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

```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.

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:

```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 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.

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:



















```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!