import json def filter_json(data): if isinstance(data, dict): filtered_data = {} for key, value in data.items(): if key == "legacy": filtered_data[key] = value elif isinstance(value, (dict, list)): filtered_value = filter_json(value) if filtered_value: filtered_data[key] = filtered_value return filtered_data elif isinstance(data, list): filtered_data = [] for item in data: filtered_item = filter_j