If you would like to keep the line breaks, you might try:
function parse($text) {
// Damn pesky carriage returns...
$text = str_replace("\r\n", "\n", $text);
$text = str_replace("\r", "\n", $text);
// JSON requires new line characters be escaped
$text = str_replace("\n", "\\n", $text);
return $text;
}