import json # Load the dataset file file_path = '/home/yiyangai/stephenqs/datasets/mehrankazemi___re_mi/remi_dataset-02.json' # Load the data from the file with open(file_path, 'r') as f: data = json.load(f) # Function to remove the first "image": null entry after "id" def remove_first_image_null(data): for item in data: if item.get("image") is None: item.pop("image", None) return data # Apply the function updated_data = remove_first_image_null(data) # Save the updated dataset to a new file updated_file_path = '/home/yiyangai/stephenqs/datasets/mehrankazemi___re_mi/remi-02.json' with open(updated_file_path, 'w') as f: json.dump(updated_data, f, indent=4) print("First 'image': null entries removed successfully.")