setup / utils /write_to_json.py
AnanthulaShravya's picture
Rename write_to_json.py to utils/write_to_json.py
092b4d2 verified
raw
history blame contribute delete
346 Bytes
import json
def write_dict_to_json(data, filename="data.json", indent=4):
try:
with open(filename, 'w') as json_file:
json.dump(data, json_file, indent=indent)
print(f"Successfully wrote dictionary to {filename}")
except (IOError, json.JSONDecodeError) as e:
print(f"Error writing to JSON file: {e}")