from decimal import Decimal    
from datetime import datetime, date, time

def convertir_decimales(obj):
    if isinstance(obj, list):
        return [convertir_decimales(x) for x in obj]
    elif isinstance(obj, dict):
        return {k: convertir_decimales(v) for k, v in obj.items()}
    elif isinstance(obj, Decimal):
        return float(obj)
    else:
        return obj
    

def convertir_fechas(obj):
    """
    Convierte objetos datetime, date y time a su representación ISO 8601.
    """
    if isinstance(obj, list):
        return [convertir_fechas(x) for x in obj]
    elif isinstance(obj, dict):
        return {k: convertir_fechas(v) for k, v in obj.items()}
    elif isinstance(obj, (datetime, date, time)):
        return obj.isoformat()
    else:
        return obj
    

def limpiar_datos_para_json(data):
    data = convertir_decimales(data)
    data = convertir_fechas(data)
    return data