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 modify or discard it.