Putting it Together: Read a JSON file
Learn to read and write a JSON file with Python.
We'll cover the following
Reading a JSON file
A very common task in any language is reading, editing and writing a file. As a quick demo, we are going to write a full Python program that does the following:
- Reads a JSON file from disk
- De-serializes the data into a Python
dict
- Modifies the
dict
by changing a value - Serializes the
dict
back to JSON - Writes the final JSON back to a file
Let’s start by reading the file using Python’s open()
function, and printing the file contents.
Get hands-on with 1200+ tech skills courses.