Putting it Together: Read a JSON file
The topic explains how to read, modify, and write JSON files in Python. It involves using the `open()` function to read the file, utilizing the `with` statement for safe file handling, de-serializing the data into a Python dictionary, modifying the dictionary, and then using `json.dump()` to write the updated data back to a JSON file. An exercise prompts the reader to enhance a function to add a "Strawberry" entry to the data.
We'll cover the following...
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