Spaces:
Sleeping
Sleeping
| 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}") | |