I am encoding my array to JSON format but it is not breaking line from the new line operator (\n).
So how to achieve this
$array = ["string" => "hello \ngood morning!!"];
$encodedJson = json_encode($array);
dd(encodedJson);
Outputs
{"string":"hello \ngood morning!!"}
But what I wanted is
{
"string" :"hello
good morning!!"
}
I also tried
json_encode($array,JSON_UNESCAPED_LINE_TERMINATORS);
What you want is not valid JSON.
The JSON data format does not support literal new lines in the middle of strings.
There is no way to make json_encode produce that output (and if you could, you then couldn't parse the result in any standard JSON parser).