serialize: Remove allocations from escaping strs and indenting spaces

This speeds up json serialization by removing most of the allocations.
This is a lot of write calls. It would be nice if this could be written to use as few write calls as possible, in case the `Writer` isn't buffered.