Spaces:
Runtime error
Runtime error
File size: 346 Bytes
c232c71 | 1 2 3 4 5 6 7 8 9 10 | 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}")
|