Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

290
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda