import csv import json def convert_csv_to_json_simple(csv_file_path, json_file_path): """ Converts a CSV file to a JSON file, keeping the problem description as a single text block. """ problems = [] with open(csv_file_path, mode='r', encoding='utf-8') as csv_file: csv_reader = csv.DictReader(csv_file) for row in csv_reader: # Clean up keys from the CSV header cleaned_row = {key.strip().replace(' ', '_').replace('.', ''): value for key, value in row.items()} problem_data = { 's_no': int(cleaned_row.get('SNo', 0)), 'organization': cleaned_row.get('Organization', ''), 'title': cleaned_row.get('Problem_Statement_Title', ''), 'category': cleaned_row.get('Category', ''), 'ps_number': cleaned_row.get('PS_Number', ''), 'submitted_ideas_count': int(cleaned_row.get('Submitted_Ideas_Count', 0)), 'theme': cleaned_row.get('Theme', ''), 'problem_description': cleaned_row.get('Problem_Description', '').strip() } problems.append(problem_data) with open(json_file_path, mode='w', encoding='utf-8') as json_file: json.dump({"problems": problems}, json_file, indent=4) if __name__ == '__main__': csv_input_file = 'SIH_Problem_Statements.csv' json_output_file = 'SIH_Problem_Statements.json' convert_csv_to_json_simple(csv_input_file, json_output_file) print(f"Successfully converted '{csv_input_file}' to '{json_output_file}'")