Created
February 5, 2021 15:20
-
-
Save dominiksimgen/a6c49a57559ee17c7ffcf04ce9d9fc64 to your computer and use it in GitHub Desktop.
how to read and write to JSON files with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, os | |
here = os.path.dirname(os.path.abspath(__file__)) | |
os.chdir(here) | |
f = open("database/locations.json", "r") # open the JSON with read access | |
data = json.load(f) | |
f.close() | |
#do here something with the "data" object like reading and manipulating data | |
f = open("database/locations.json", "w") # open the JSON with write access | |
json.dump(data, f) # dump the "data" object to the JSON | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment