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

254
Vistas
How to update JSON keys in place?

I would like to add a set of escaped quote around all first level keys in a JSON object.

const j = '{"a": "b", "c": "d"}';
let obj = JSON.parse(j);

Object.keys(obj).forEach(k => {
  k = `\"${k}\"`;
});

console.log(JSON.stringify(obj, null, 2));

which of course gives

{
  "a": "b",
  "c": "d"
}

as I need to do the substitution in the actual object.

But how can I update the keys in place?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

This should work. Just define a new key and give it the same value as the old key, then delete the old key.

const j = '{"a": "b", "c": "d"}';
let obj = JSON.parse(j);

Object.keys(obj).forEach(k => {
 obj[`\"${k}\"`] = obj[k];
 delete obj[k];
});

console.log(JSON.stringify(obj, null, 2));

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