Use a buffer to encode JSON