Improve control character handling in JSON strings
Previously we stripped out all newlines and left in numerous other control
characters that would result in errors with JSON.parse(). With this change
all control characters are kept and escaped following the guidelines at: