Turns out JSON doesn't allow \0 as an escape sequence. Also, don't rely on is_print for figuring out which characters to escape, but instead follow the spec. Fixes bug 3827.