import pandas as pd import json data = [] df = pd.read_csv('QA.csv') for index, row in df.iterrows(): for column in df.columns: # print(f"{column}: {row[column]}") # remove the white space if isinstance(row[column], str): row[column] = row[column].replace(' ','').replace(' ','') data.append(row.to_dict()) with open('QA.json', 'w') as f: json.dump(data, f, ensure_ascii=False, indent=4) print("Done")