improved json encoding handling for cross platform support