def rec_key_replace(obj):
    if isinstance(obj, Mapping):
        return {key.replace('.', '_'): rec_key_replace(val) for key, val in
            list(obj.items())}
return obj
Recursively replace characters in a dictionary