You should be using json_encode, wich will generate a JSON string that contains \r\n
for line breaks. Then you will have to replace each \r\n
occurences by <br>
tags.
echo str_replace('\r\n','<br>', json_encode(array("success"=>"true","data"=>$a,"type"=>"text")));