escape newline character before serializing