Abstract JSON send

This also appends a newline to JSON to be sent. This makes socket buffering more straightforward for clients.