Q:

How to end a JSON file with "\r\n"?

I have been working around with JSON files in python lately for an assignment and one thing is still unclear to me, yet Ive reached a point in it where I have to address it:

The communication to the server is done through a TCP socket, exchanging JSON objects that end with the characters \r\n.

I have an issue though: How do I make my JSON files in python end that way?
Here is some code for a simple JSON object creation:
json.dumps({'test': 'EXAMPLE'}, sort_keys=True, indent=4)

The sort_keys is there for other exercises in the project. This object does not end with \r\n though.
Overall, what I need help with:
What would "ending with \r\n" mean in terms of JSON and how would it impact the file itself?
Thank you and have a good day.
How would I do it in Python?

A:

\r is a means of expressing the carriage return character -- a control signal which sends the cursor back to the beginning of the line. \n is a linefeed -- a signal which sends the cursor down to the next line.
On DOS and Windows, \r\n (aka CRLF) is the traditional way to end a line of text. Presumably, then, this means that your software is expected to write a JSON document on one line, followed by a DOS/Windows-style newline.
socket.write(json.dumps({'test': 'EXAMPLE'}, sort_keys=True) + '\r\n')

Note that indent=4 is not specified here, because setting any value other than None for indent means that you want your data split onto multiple (indented) lines -- whereas if your format ends in \r\n, that implies that the data is all expected to be on a single line.

