def _replace_strings(obj, old, new, inplace=False):
    """
    Recursively replaces all strings in the given object.

    This function is specifically meant to help with saving and loading
    of config dictionaries and should not be considered a general tool.
    """
    if not inplace:
        obj = obj.copy()

    if isinstance(obj, dict):
        obj_keys = obj.keys()
    elif isinstance(obj, list):
        obj_keys = range(len(obj))
    else:
        raise TypeError('Object must be either a dict or a list.')

    for key in obj_keys:
        if isinstance(obj[key], str):
            obj[key] = obj[key].replace(old, new)
        elif isinstance(obj[key], dict) or isinstance(obj[key], list):
            obj[key] = _replace_strings(obj[key], old, new)

    return obj