W3docs

Reading JSON from a file

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

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

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)

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Python - The Practical Guide</div>

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.