rewrite json object values (unicode) into utf-8 encoded string

def any2utf8(data):
    """
        rewrite json object values (unicode) into utf-8 encoded string
    """
    if isinstance(data, dict):
        ret = {}
        for k, v in data.items():
            k = any2utf8(k)
            ret[k] = any2utf8(v)
        return ret
    elif isinstance(data, list):
        return [any2utf8(x) for x in data]
    elif isinstance(data, unicode):
        return data.encode("utf-8")
    elif type(data) in [str, basestring]:
        return data
    elif type(data) in [int, float]:
        return data
    else:
        logging.error("unexpected {} {}".format(type(data), data))
        return data