Spaces:
Running
Running
import pandas as pd | |
def json_to_csv(json_filepath, csv_filepath): | |
""" | |
Converts a JSON file to a CSV file. | |
Args: | |
json_filepath (str): The path to the input JSON file. | |
csv_filepath (str): The path to the output CSV file. | |
""" | |
try: | |
df = pd.read_json(json_filepath) | |
df.to_csv(csv_filepath, index=False) | |
print(f"Successfully converted '{json_filepath}' to '{csv_filepath}'") | |
except FileNotFoundError: | |
print(f"Error: JSON file '{json_filepath}' not found.") | |
except Exception as e: | |
print(f"An error occurred: {e}") | |
# Example usage | |
json_file = 'activity2sound.json' | |
csv_file = 'data.csv' | |
json_to_csv(json_file, csv_file) |