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

66
Visualizações
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 à 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