Made safe environment copy

As json is not able to process byte strings correctly, I tried to fix https://github.com/saltstack/salt/issues/12399 by this. Feel free to modify or to discard it if you have a better solution.