xxxxxxxxxx
# Reading dictionary from a json file
json.load(open('1.json', 'r'))
xxxxxxxxxx
import json
# Dictionary to be saved
my_dict = {'key1': 'value1', 'key2': 'value2'}
# Open a file for writing
with open('dict.txt', 'w') as f:
# Write the dictionary to the file in JSON format
json.dump(my_dict, f)
xxxxxxxxxx
dictionary = {'someKey' : 'someValue'}
file_path = 'somePathToFile/someFileName.py'
with open(file_path, 'w') as output_file:
print(dictionary, file=output_file)
xxxxxxxxxx
# Writing dictionary as json
import json
d = {'guitar':'Jerry', 'drums':'Mickey' }
json.dump(d, open('1.json', 'w'))