Improved json encoding.