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

67
Vistas
Editing a JSON value in varying depth

I got a JSON File in which some data is saved. What I want to do is create a function that can be globally used to edit a value. Problem here is that there are different depths and designations of the elements.

Example.json

{ 
  "val": 1,
  "categ": {
    "subcateg": {
      "val1": "#000000",
      "val2": ["123"]
    },
    "subcateg2": {
      "val1": "#000000",
      "val2": ["234"]
    }
  },
  "val1": ["123"],
  "val2": "text stuff",
  "categ2": {
    "id": "123",
    "content": "Hello this is a test"
  }
  .
  .
  .
}

So in the end I want to be able to edit every single value of these.

Current

Until now I just found the solution to do this with eval() but ik it's unsecure so I want a new solution

function json_d_w(keys, value) { // keys: Array, value: any
    json_d_r('', (data) => { // reads the data from the JSON file
        var s = 'data';
        for (var x = 0; x < keys.length; x++) { s += `['${keys[x]}']` }
        eval(s+=' = value');
        return s;
    });
}

So as mentioned before I try to change this to a more secure method but didn't find any in the internet

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