so i have a JSON file that has data structured like this:

[
	[
	    {
	        "Input": [
	            [
	                "PatientID",
	                "TreatmentDate",
	                "TreatmentType",
	                "DoctorID",
	                "TreatmentCost"
	            ],
	            [
	                "PatientID",
	                "Age",
	                "Gender",
	                "InsuranceType",
	                "Region"
	            ],
	            [
	                "DoctorID",
	                "DoctorName",
	                "Specialization",
	                "YearsOfExperience",
	                "HospitalID"
	            ]
	        ],
	        "Output": {
	            "SectorClassification": "Healthcare",
	            "Overview": "This dataset represents patient treatment data, linking patient demographics with treatment details and doctor specialization. It supports analyses into treatment costs, patient demographics, and doctor performance to optimize healthcare services and resources.",
	            "ImportantColumns": [
	                {
	                    "PatientID": "Links patient-specific information to their treatments, enabling analysis of individual patient histories."
	                },
	                {
	                    "TreatmentDate": "Identifies when a treatment was performed, supporting temporal analysis of healthcare trends, like seasonal variations in patient admissions."
	                },
	                {
	                    "TreatmentType": "Defines the type of treatment received, which allows for analysis of common treatments and their costs."
	                },
	                {
	                    "InsuranceType": "Indicates the insurance coverage of the patient, providing insights into financial aspects of healthcare provision."
	                },
	                {
	                    "DoctorID": "Connects treatments with specific doctors, enabling performance analysis and resource allocation."
	                }
	            ],
	            "SuggestedPlots": [
	                {
	                    "plot_type": "line",
	                    "x-axis": "TreatmentDate",
	                    "y-axis": "TreatmentCost"
	                },
	                {
	                    "plot_type": "bar",
	                    "x-axis": "TreatmentType",
	                    "y-axis": "TreatmentCost"
	                },
	                {
	                    "plot_type": "pie",
	                    "category": "InsuranceType",
	                    "values": "TreatmentCost"
	                },
	                {
	                    "plot_type": "histogram",
	                    "x-axis": "Age",
	                    "y-axis": "frequency"
	                }
	            ],
	            "PlotExplanation": [
	                {
	                    "plot_type": "line",
	                    "description": "A line chart showing TreatmentDate versus TreatmentCost reveals temporal trends in healthcare expenditures, identifying cost spikes or reductions over time."
	                },
	                {
	                    "plot_type": "bar",
	                    "description": "A bar chart mapping TreatmentType versus TreatmentCost highlights the cost distribution across different treatments, showing where most resources are spent."
	                },
	                {
	                    "plot_type": "pie",
	                    "description": "A pie chart comparing InsuranceType versus TreatmentCost shows the proportion of costs covered by different insurance types, offering insights into financial management."
	                },
	                {
	                    "plot_type": "histogram",
	                    "description": "A histogram of Age shows the distribution of patients by age, supporting demographic insights on treatment patterns and resource needs."
	                }
	            ],
	            "Insights": [
	                {
	                    "Category": "Cross-Table Relationships",
	                    "Insight": "By linking PatientID across tables, it\u2019s possible to analyze how patient demographics, such as age and insurance type, impact treatment costs and types."
	                },
	                {
	                    "Category": "Cross-Table Relationships",
	                    "Insight": "The DoctorID field connects specific treatments with doctors, which can be used to assess treatment outcomes and doctor performance."
	                },
	                {
	                    "Category": "Temporal Relationships",
	                    "Insight": "The TreatmentDate column helps identify seasonal trends in patient treatments, such as higher incidences of specific diseases in colder months."
	                },
	                {
	                    "Category": "Categorical Relationships",
	                    "Insight": "InsuranceType allows segmentation of patients by their coverage, enabling insights into financial patterns and healthcare accessibility."
	                },
	                {
	                    "Category": "Statistical Relationships",
	                    "Insight": "The Age column enables comparison of treatment costs and frequency across different age groups, helping prioritize resource allocation."
	                }
	            ]
	        }
	    },
	    {
	        "Input": [
	            [
	                "HospitalID",
	                "ResourceID",
	                "ResourceType",
	                "Availability",
	                "UtilizationRate"
	            ],
	            [
	                "HospitalID",
	                "HospitalName",
	                "Location",
	                "BedsAvailable",
	                "Specialization"
	            ],
	            [
	                "ResourceID",
	                "ResourceName",
	                "CostPerUnit",
	                "Category",
	                "Supplier"
	            ]
	        ],
	        "Output": {
	            "SectorClassification": "Healthcare",
	            "Overview": "This dataset tracks hospital resource utilization, linking hospitals, resources, and their usage. It supports analysis of hospital efficiency, resource allocation, and cost management, aiming to optimize healthcare service delivery.",
	            "ImportantColumns": [
	                {
	                    "HospitalID": "Links hospitals with their specific resources, facilitating analysis of resource availability and utilization within each hospital."
	                },
	                {
	                    "ResourceType": "Identifies the type of resource (e.g., medical equipment, staff), enabling analysis of resource needs and bottlenecks."
	                },
	                {
	                    "UtilizationRate": "Indicates the percentage of resource usage, crucial for understanding resource efficiency and identifying underutilized or overused resources."
	                },
	                {
	                    "BedsAvailable": "Reflects the hospital\u2019s capacity, supporting analysis of bed utilization and patient flow management."
	                },
	                {
	                    "CostPerUnit": "Shows the cost of each resource, providing insights into resource expenses and supporting budget allocation decisions."
	                }
	            ],
	            "SuggestedPlots": [
	                {
	                    "plot_type": "bar",
	                    "x-axis": "ResourceType",
	                    "y-axis": "UtilizationRate"
	                },
	                {
	                    "plot_type": "pie",
	                    "category": "Specialization",
	                    "values": "BedsAvailable"
	                },
	                {
	                    "plot_type": "line",
	                    "x-axis": "ResourceID",
	                    "y-axis": "CostPerUnit"
	                },
	                {
	                    "plot_type": "radar_chart",
	                    "parameters": "ResourceType, UtilizationRate, CostPerUnit"
	                }
	            ],
	            "PlotExplanation": [
	                {
	                    "plot_type": "bar",
	                    "description": "A bar chart mapping ResourceType to UtilizationRate shows which types of resources are over- or under-utilized in the hospital."
	                },
	                {
	                    "plot_type": "pie",
	                    "description": "A pie chart comparing hospital specializations to available beds helps identify whether certain specializations require more or fewer resources."
	                },
	                {
	                    "plot_type": "line",
	                    "description": "A line graph showing ResourceID versus CostPerUnit reveals cost patterns across different types of hospital resources."
	                },
	                {
	                    "plot_type": "radar_chart",
	                    "description": "A radar chart comparing ResourceType, UtilizationRate, and CostPerUnit helps evaluate the balance between resource demand and expense."
	                }
	            ],
	            "Insights": [
	                {
	                    "Category": "Cross-Table Relationships",
	                    "Insight": "By linking HospitalID, resource types can be compared across different hospitals, allowing for analysis of resource allocation strategies and hospital performance."
	                },
	                {
	                    "Category": "Categorical Relationships",
	                    "Insight": "The ResourceType field helps identify which resources are most critical to hospital operations, guiding resource procurement and staffing strategies."
	                },
	                {
	                    "Category": "Statistical Relationships",
	                    "Insight": "UtilizationRate combined with CostPerUnit allows for a cost-benefit analysis, highlighting resources with high usage and high expense."
	                },
	                {
	                    "Category": "Temporal Relationships",
	                    "Insight": "Hospital resource data over time can reveal patterns in resource demand, helping plan for peak times like flu seasons."
	                }
	            ]
	        }
	    },
	    {
	        "Input": [
	            [
	                "AdmissionID",
	                "PatientID",
	                "AdmissionDate",
	                "DischargeDate",
	                "DiagnosisCode"
	            ],
	            [
	                "PatientID",
	                "Name",
	                "Age",
	                "Gender",
	                "InsuranceType"
	            ],
	            [
	                "DiagnosisCode",
	                "DiagnosisName",
	                "Severity",
	                "TreatmentRequired"
	            ]
	        ],
	        "Output": {
	            "SectorClassification": "Healthcare",
	            "Overview": "This dataset tracks patient admission and discharge records, linking patient demographics with their diagnoses and treatment durations. It supports analyses into patient flow, diagnosis trends, and healthcare utilization across different demographic groups.",
	            "ImportantColumns": [
	                {
	                    "AdmissionID": "Unique identifier for each admission, helping track patient stays, diagnoses, and discharge details."
	                },
	                {
	                    "PatientID": "Links patient demographic data (e.g., age, gender) to their admission and discharge records, enabling personalized healthcare insights."
	                },
	                {
	                    "AdmissionDate": "Indicates when a patient was admitted, helping analyze hospital occupancy and patient flow over time."
	                },
	                {
	                    "DiagnosisCode": "Associates patients with specific diagnoses, allowing for the identification of common conditions and their treatment patterns."
	                },
	                {
	                    "Severity": "Describes the severity of the condition, helping prioritize patient treatment and hospital resource allocation."
	                }
	            ],
	            "SuggestedPlots": [
	                {
	                    "plot_type": "line",
	                    "x-axis": "AdmissionDate",
	                    "y-axis": "Count of Admissions"
	                },
	                {
	                    "plot_type": "bar",
	                    "x-axis": "DiagnosisCode",
	                    "y-axis": "Count of Patients"
	                },
	                {
	                    "plot_type": "pie",
	                    "category": "Severity",
	                    "values": "Count of Patients"
	                },
	                {
	                    "plot_type": "histogram",
	                    "x-axis": "Age",
	                    "y-axis": "Frequency"
	                }
	            ],
	            "PlotExplanation": [
	                {
	                    "plot_type": "line",
	                    "description": "A line chart of AdmissionDate versus Count of Admissions helps visualize trends in hospital admissions over time, such as seasonal surges in illness."
	                },
	                {
	                    "plot_type": "bar",
	                    "description": "A bar chart of DiagnosisCode versus Count of Patients highlights the most common diagnoses, supporting resource planning and disease prevention strategies."
	                },
	                {
	                    "plot_type": "pie",
	                    "description": "A pie chart of Severity versus Count of Patients illustrates the distribution of patient severity, aiding in triage and resource allocation."
	                },
	                {
	                    "plot_type": "histogram",
	                    "description": "A histogram of Age versus Frequency helps analyze the age distribution of admitted patients, supporting targeted healthcare strategies."
	                }
	            ],
	            "Insights": [
	                {
	                    "Category": "Cross-Table Relationships",
	                    "Insight": "By linking PatientID across tables, it's possible to analyze how different demographics (age, gender, insurance type) affect admission rates and hospital stay durations."
	                },
	                {
	                    "Category": "Temporal Relationships",
	                    "Insight": "The AdmissionDate column helps track patient flow, identifying peak periods of admission and supporting hospital capacity planning."
	                },
	                {
	                    "Category": "Categorical Relationships",
	                    "Insight": "DiagnosisCode allows categorization of patients based on their condition, helping identify trends in diseases and focus resources on high-severity cases."
	                },
	                {
	                    "Category": "Statistical Relationships",
	                    "Insight": "The Severity column enables analysis of the correlation between diagnosis severity and patient outcomes, such as length of stay or treatment costs."
	                },
	                {
	                    "Category": "Cross-Table Relationships",
	                    "Insight": "The AdmissionID links patient stays with specific diagnoses, providing insights into treatment patterns and patient recovery times."
	                }
	            ]
	        }
	    },
	    {
	        "Input": [
	            [
	                "HospitalID",
	                "StaffID",
	                "Role",
	                "HoursWorked",
	                "Salary"
	            ],
	            [
	                "HospitalID",
	                "HospitalName",
	                "Location",
	                "BedsAvailable",
	                "TotalStaff"
	            ],
	            [
	                "StaffID",
	                "StaffName",
	                "Specialization",
	                "YearsOfExperience",
	                "Qualification"
	            ]
	        ],
	        "Output": {
	            "SectorClassification": "Healthcare",
	            "Overview": "This dataset represents hospital staffing and operations, linking hospital resources with staff roles and work hours. It supports analyses of staffing efficiency, resource utilization, and compensation trends across healthcare facilities.",
	            "ImportantColumns": [
	                {
	                    "HospitalID": "Links staff details and hospital data, enabling analysis of staffing levels relative to hospital capacity and patient needs."
	                },
	                {
	                    "StaffID": "Connects specific staff members to their work hours and roles, supporting performance evaluation and staffing optimization."
	                },
	                {
	                    "Role": "Defines the staff role (e.g., nurse, doctor, admin), allowing for role-based analysis of salary distributions and hours worked."
	                },
	                {
	                    "HoursWorked": "Represents the total hours worked by each staff member, helping track staffing efficiency and overworked staff."
	                },
	                {
	                    "Salary": "Shows the salary for each staff member, enabling compensation analysis and identifying any disparities between roles or experience levels."
	                }
	            ],
	            "SuggestedPlots": [
	                {
	                    "plot_type": "bar",
	                    "x-axis": "Role",
	                    "y-axis": "Salary"
	                },
	                {
	                    "plot_type": "line",
	                    "x-axis": "HospitalID",
	                    "y-axis": "HoursWorked"
	                },
	                {
	                    "plot_type": "pie",
	                    "category": "Role",
	                    "values": "StaffID"
	                },
	                {
	                    "plot_type": "scatter",
	                    "x-axis": "YearsOfExperience",
	                    "y-axis": "Salary"
	                }
	            ],
	            "PlotExplanation": [
	                {
	                    "plot_type": "bar",
	                    "description": "A bar chart of Role versus Salary helps compare salaries across different staff roles, identifying any inequities or discrepancies."
	                },
	                {
	                    "plot_type": "line",
	                    "description": "A line chart of HospitalID versus HoursWorked shows staffing patterns across different hospitals, supporting workload distribution and staffing needs."
	                },
	                {
	                    "plot_type": "pie",
	                    "description": "A pie chart of Role versus StaffID shows the proportion of each staff role in the healthcare facility, supporting workforce planning."
	                },
	                {
	                    "plot_type": "scatter",
	                    "description": "A scatter plot of YearsOfExperience versus Salary reveals the relationship between staff experience and compensation, helping assess pay equity."
	                }
	            ],
	            "Insights": [
	                {
	                    "Category": "Cross-Table Relationships",
	                    "Insight": "By linking StaffID across tables, it\u2019s possible to analyze how different staff roles impact hospital operations and staff compensation relative to hospital capacity."
	                },
	                {
	                    "Category": "Temporal Relationships",
	                    "Insight": "The HoursWorked column can be used to identify trends in staff workload over time, helping manage staffing levels based on hospital activity."
	                },
	                {
	                    "Category": "Categorical Relationships",
	                    "Insight": "Role allows for staff categorization by their position, enabling targeted compensation analysis and resource allocation for each role."
	                },
	                {
	                    "Category": "Statistical Relationships",
	                    "Insight": "The YearsOfExperience column allows for analysis of the correlation between experience and salary, providing insights into compensation equity and retention."
	                },
	                {
	                    "Category": "Cross-Table Relationships",
	                    "Insight": "The HospitalID connects hospital staffing levels to the available beds, allowing for analysis of how staffing impacts hospital capacity and patient care quality."
	                }
	            ]
	        }
	    }
]


now look at the input section of each entry.

I wanted them to look like this:

"Input": [
		      ["PatientID", "AdmissionID", "AdmissionDate", "DischargeDate", "DiagnosisID", "TreatmentPlanID", "ERDoctorID"],
		      ["PatientID", "Name", "Age", "Gender", "ContactInfo", "InsuranceStatus"],
		      ["AdmissionID", "AdmissionType", "SeverityLevel", "InitialSymptoms"],
		      ["DiagnosisID", "DiagnosisType", "DiagnosisDetails"],
		      ["TreatmentPlanID", "TreatmentType", "DoctorID", "TreatmentDetails"],
		      ["ERDoctorID", "DoctorName", "Specialization", "HospitalID"]
		   ],

but instead they ended up being the way thery are.


i already have a code this:

import json
from collections import defaultdict

def load_dataset(filepath):
    """Load the dataset JSON file."""
    with open(filepath, "r") as file:
        return json.load(file)

def normalize_output(output):
    """Normalize the Output dictionary by converting lists and dicts inside it to hashable types."""
    normalized_output = {}
    for key, value in output.items():
        if isinstance(value, list):  # Convert list to tuple
            normalized_output[key] = tuple(normalize_list(value))  
        elif isinstance(value, dict):  # Convert dict to tuple of key-value pairs
            normalized_output[key] = tuple(normalize_dict(value))
        else:
            normalized_output[key] = value  # Keep non-dict/non-list values as is
    return normalized_output

def normalize_list(value):
    """Recursively convert lists and their inner elements to hashable structures."""
    return [tuple(normalize_list(item)) if isinstance(item, list) else
            tuple(normalize_dict(item)) if isinstance(item, dict) else
            item for item in value]

def normalize_dict(value):
    """Recursively convert a dictionary to a hashable tuple of key-value pairs."""
    return ((k, tuple(normalize_list(v)) if isinstance(v, list) else 
                 tuple(normalize_dict(v)) if isinstance(v, dict) else v)
            for k, v in value.items())

def check_dataset_health(dataset):
    """Check for incomplete data, count entries by sector, and flag structural issues."""
    incomplete_entries = []       # Track incomplete entries
    sector_counts = defaultdict(int)  # Count entries by sector

    for i, entry in enumerate(dataset):
        # Increment count for the sector
        sector = entry.get("Output", {}).get("SectorClassification", "Unknown")
        sector_counts[sector] += 1

        # Check for missing Input or Output
        if not entry.get("Input") or not entry.get("Output"):
            incomplete_entries.append((i, "Missing Input or Output entirely"))
            continue

        # Check if Input tables have at least 4 columns
        if not all(isinstance(table, list) and len(table) >= 4 for table in entry["Input"]):
            incomplete_entries.append((i, "Some Input tables are incomplete or less than 4 columns"))

        # Check Output fields are missing
        output = entry["Output"]
        required_fields = ["SectorClassification", "Overview", "ImportantColumns", "SuggestedPlots", "PlotExplanation", "Insights"]
        missing_fields = [field for field in required_fields if field not in output]
        if missing_fields:
            incomplete_entries.append((i, f"Missing Output fields: {missing_fields}"))

    return sector_counts, incomplete_entries

def remove_duplicates(dataset):
    """Remove duplicate entries from the dataset."""
    seen_entries = set()      # To track unique entries
    cleaned_dataset = []      # To store unique entries

    for entry in dataset:
        # Normalize Input and Output sections for comparison
        input_entry = tuple([tuple(table) for table in entry["Input"]])  # Normalize Input
        output_entry = tuple(normalize_output(entry["Output"]).items())  # Normalize Output
        
        # Combine Input and Output for full entry uniqueness
        full_entry = (input_entry, output_entry)
        
        if full_entry not in seen_entries:  # If entry is not a duplicate
            seen_entries.add(full_entry)   # Mark entry as seen
            cleaned_dataset.append(entry)  # Add unique entry to the cleaned dataset

    return cleaned_dataset

def print_sector_counts(sector_counts, stage):
    """Print sector counts in a readable format."""
    print(f"\n{stage} Sector Counts:")
    for sector, count in sector_counts.items():
        print(f"    {sector}: {count}")

def save_to_json(dataset, filepath):
    """Save the cleaned dataset back to the original file."""
    with open(filepath, "w") as file:
        json.dump(dataset, file, indent=4)
    print(f"Cleaned dataset saved back to {filepath}")

def main(filepath):
    # Load the original dataset
    dataset = load_dataset(filepath)
    print(f"Initial dataset contains {len(dataset)} entries.")

    # Check dataset health
    sector_counts, incomplete_entries = check_dataset_health(dataset)
    print_sector_counts(sector_counts, "Initial")  # Print initial sector counts
    if incomplete_entries:
        print(f"\nIncomplete Entries Found: {len(incomplete_entries)}")
        for entry in incomplete_entries:
            print(f" - Entry {entry[0]}: {entry[1]}")

    # Remove duplicates
    cleaned_dataset = remove_duplicates(dataset)
    print(f"\nCleaned dataset contains {len(cleaned_dataset)} unique entries (duplicates removed).")

    # Recalculate sector counts for cleaned dataset
    cleaned_sector_counts, _ = check_dataset_health(cleaned_dataset)
    print_sector_counts(cleaned_sector_counts, "Cleaned")  # Print cleaned sector counts

    # Save cleaned dataset back to the original file
    save_to_json(cleaned_dataset, filepath)

    print("\nAnalysis Complete. Dataset cleaned and saved back to the original file.")

if __name__ == "__main__":
    # Provide the path to your dataset JSON file
    filepath = "/Users/magi/Documents/projects/AI-CRM/LLM-dataset.json"  # Input dataset path
    main(filepath)


can you update this code to also alter the input section to the way i wanted them to be as i mentioned above ?