After json_encode, "\ n" becomes "\\ n".

json_encode"\n""\\n"
 : \n
:\\n
json_encode  320
JSON_UNESCAPED_SLASHES 64 + JSON_UNESCAPED_UNICODE  256

 \\n
Php
May.31,2022

depends on whether you want to use \ n as a newline character or an ordinary string, define it with "" as a newline character, and use '' as an ordinary string.

In

JSON format data, \ n is the newline character
"I love learning\ n" , \ n is the newline character
'I love learning\ n', \ n is an ordinary string

therefore, the ordinary string \ n should be escaped when it becomes JSON data to avoid being treated as a newline

.

// 
echo json_encode('[\n]').PHP_EOL; //  "[\\n]"
echo json_encode("[\n]").PHP_EOL; //  "[\n]"
Menu