def json_datetime_encoder(obj):
    """Use as a json.dump default= function to encode datetimes as isoformat strings."""
    try:
        return obj.isoformat()
    except:
        raise TypeError('Object of type %s with value of %s is not JSON serializable' % (type(obj), repr(obj)))