Line breaks within text field



Does anyone know how twitter handles line breaks within the text field in the JSON they return? Do they just include a ‘\n’ character or just ignore it? I’ve looked around and can’t seen to find an answer.

I’m asking because I have a load of tweets saved to a txt file with each tweet on a new line. The problem is that when I read in the txt file I end up with more entries than there are lines in the file. I’ve checked everything else and the last thing I can think of is that some of the tweets contain a ‘\n’ and are being split across multiple entries.


Yes, tweets escape newlines with \n, so the JSON you get from the API should be something like:


If you’ve saved those in a file, and ended up with:


You’ll need to fix that somehow (replace any newline character with \n if it’s in the “text” field).


Thanks IgorBrigadir! That was it! Added something to take care of that and the problem is solved.