Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

285
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda