serialize: Remove allocations from escaping strs and indenting spaces

This speeds up json serialization by removing most of the allocations.
Same here, I would love to see the number of write calls reduced in case the output isn't buffered. You could perhaps use a 16-byte stack array in order to write up to 16 spaces at one time.