Now, let's begin by reading a JSON file as a text file. We'll try this on a file containing users' names:
with open('user_name.json', 'r') as file:
Let's briefly review this code. The
with statement automatically manages closing the files after we are done working with them. The
open() function "opens" a file, and the mode (
'w', etc.) is added as an argument to specify what we intend to do with the file (reading, writing, or something else). Then we extract a string containing all characters in the file using
read(). If any of this is new to you, we recommend that you check out our course Python Basics Part 2.