import os import json def process_json_file(file_path): # Read the JSON file with open(file_path, 'r') as file: data = json.load(file) # Extract the desired keys desired_keys = ["PatientAge", "PatientSex", "Manufacturer", "RescaleIntercept", "RescaleSlope"] cleaned_data = {key: data[key] for key in desired_keys if key in data} # Write the cleaned JSON back to the file with open(file_path, 'w') as file: json.dump(cleaned_data, file, indent=4) def scan_folder(folder_path): for root, dirs, files in os.walk(folder_path): for file in files: if file.endswith('.json'): file_path = os.path.join(root, file) process_json_file(file_path) # Provide the folder path to start the scanning folder_path = 'ctvit-transformer' scan_folder(folder_path)