Reading JSON from a file

Here is an example of reading a JSON file in Python:

import json

# Open the file
with open('data.json') as json_file:
    data = json.load(json_file)

# Access the data
print(data)

Watch a course Python - The Practical Guide

This code snippet opens the file data.json using the open() function, reads its contents using json.load(), and assigns the resulting data to the variable data. You can then access the data stored in the file by printing the data variable or by accessing its properties directly.