def json_changebase(obj, changer):
    """
    Given a primitive compound Python object (i.e. a dict,
    string, int, or list) and a changer function that takes
    a primitive Python object as an argument, apply the
    changer function to the object and each sub-component.

    Return the newly-reencoded object.
    """

    if isinstance(obj, (str, unicode)):
        return changer(obj)

    elif isinstance(obj, (int, long)) or obj is None:
        return obj

    elif isinstance(obj, list):
        return [json_changebase(x, changer) for x in obj]

    elif isinstance(obj, dict):
        return dict((x, json_changebase(obj[x], changer)) for x in obj)

    else:
        raise ValueError("Invalid object")
Given a primitive compound Python object (i.e. a dict,
    string, int, or list) and a changer function that takes
    a primitive Python object as an argument, apply the
    changer function to the object and each sub-component.

    Return the newly-reencoded object.