File size: 698 Bytes
66273c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)