def serialize(obj):
    """JSON serializer for objects not serializable by default json code"""
    if isinstance(obj, datetime.datetime):
        serial = obj.isoformat(sep='T')
        return serial

    if isinstance(obj, uuid.UUID):
        serial = str(obj)
        return serial

    try:
        return obj.__dict__
    except AttributeError:
        return str(obj)
    except Exception as e:
        strval = 'unknown obj'
        exceptval = 'unknown err'
        try:
            strval = str(obj)
            exceptval = repr(e)
        except Exception:
            pass
        return 'json fail {} {}'.format(exceptval, strval)
JSON serializer for objects not serializable by default json code