from datetime import datetime


def to_serializable(val):
    """JSON serializer for objects not serializable by default"""

    if isinstance(val, datetime):
        return val.isoformat()
    elif hasattr(val, '__dict__'):
        return val.__dict__

    return val