Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
How to allow json_encode() accept \n as a new line?

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);

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!