File size: 1,611 Bytes
de21c1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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}'")