Open oldoc63 opened 1 year ago
We import the json module, open up a write-mode file under the variable json_file, and then use the json.dump() method to write to the file. json.dump() takes two arguments: first the data object, then the file object you want to save.
Naturally we can use the json library to translate Python objects to JSON as well. This is especially useful in instances where you are using a Python library to serve web pages, you would also be able to serve JSON. Let's say we have a Python dictionary we wanted to save as a JSON file: