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

235
Vistas
Add newline after each key, value using JSON.stringify()

I want to add a newline after each key value pair in an object using JSON.stringify()

In my actual code I will be getting a lot of key value pairs and having the new lines makes it easier to read.

Example code is:

let test = {'key' : ['one', 'two', 'three'], 'keyTwo' : ['one', 'two', 'three']}

let testOne = JSON.stringify(test, null, '\t')

console.log(testOne)

outputs:

{
        "key": [
                "one",
                "two",
                "three"
        ],
        "keyTwo": [
                "one",
                "two",
                "three"
        ]
}

I want:

{
        "key": [
                "one",
                "two",
                "three"
        ],
                                   // <----- newline here
        "keyTwo": [
                "one",
                "two",
                "three"
        ]
}

I have tried

let test = {'key' : ['one', 'two', 'three'] + "\\n", 'keyTwo' : ['one', 'two', 'three']+ "\\n"}

let testOne = JSON.stringify(test, null, '\t\n')

Neither work

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

let test = {'key' : ['one', 'two', 'three'], 'keyTwo' : ['one', 'two', 'three'], 'keyThree' : ['one', 'two', 'three']}

let testOne = JSON
    .stringify(test, null, "\t")
    .replaceAll(
        "],\n\t\"", 
        "],\n\n\t\""
    );
console.log(testOne);

about 4 years ago · Juan Pablo Isaza 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