serialize: speed up json pretty printing by batch writing spaces