Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

70
Views
Edición de un valor JSON en profundidad variable

Obtuve un archivo JSON en el que se guardan algunos datos. Lo que quiero hacer es crear una función que se pueda usar globalmente para editar un valor. El problema aquí es que hay diferentes profundidades y designaciones de los elementos.

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" } . . . }

Entonces, al final, quiero poder editar cada valor de estos.

Actual

Hasta ahora, solo encontré la solución para hacer esto con eval() pero no es seguro, así que quiero una nueva solución.

 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; }); }

Entonces, como se mencionó antes, intenté cambiar esto a un método más seguro, pero no encontré ninguno en Internet.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!