Fixed JSON writes, replacing newlines, etc.