def json_serializer(obj):
    """Default JSON serializer."""
    import calendar
    import datetime
    if isinstance(obj, datetime.datetime):
        if obj.utcoffset() is not None:
            obj = obj - obj.utcoffset()
        millis = int(calendar.timegm(obj.timetuple()) * 1000 + obj.
            microsecond / 1000)
        return millis
    if isinstance(obj, set):
        return list(obj)
    raise TypeError('Not sure how to serialize %s' % (obj,))
