import pandas as pd import json # Define the input and output file paths input_path = '/root/test/weitiao/data_process_bq/data/parquet_all.parquet' output_path = '/root/test/weitiao/data_process_bq/data/parquet_all.json' # Read the Parquet file into a Pandas DataFrame try: df = pd.read_parquet(input_path) print(f"Successfully loaded data from {input_path}") except FileNotFoundError: print(f"Error: The file {input_path} was not found.") exit() except Exception as e: print(f"An error occurred while reading the Parquet file: {e}") exit() # Convert the DataFrame to a list of dictionaries (records) records = df.to_dict(orient='records') # Write the data to a JSON file with open(output_path, 'w', encoding='utf-8') as f: # Use json.dump to write the list of dictionaries json.dump(records, f, ensure_ascii=False, indent=4) print(f"Successfully converted the dataset to JSON and saved to {output_path}")