Menu Close

How to read JSON from a file with Python?

Sometimes, we want to read JSON from a file with Python.

In this article, we’ll look at how to read JSON from a file with Python.

How to read JSON from a file with Python?

To read JSON from a file with Python, we can open the file with open.

Then we call json.load to read the file.

For instance, we write

import json

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

to call open to read strings.json.

Then we call json.load with file f to read it into a JSON string.

Conclusion

To read JSON from a file with Python, we can open the file with open.

Then we call json.load to read the file.

Posted in Python, Python Answers