One minute
Python: Read & Write Json
Often it is useful to save python data to json files. The following code will demonstrate how that can be done.
“God bless JSON!” ~ a soon to be famous programmer
import json
data = {'a': 1, 'b':'hello', 'c':False}
filename = 'awesome_data.json'
# write data to file
with open(filename, 'w') as f:
json.dump(data, f)
# read json from file
with open(filename, 'r') as f:
data = json.load(f)
print(data)
# prints {'a': 1, 'b':'hello', 'c':False}
Read other posts