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

65
Views
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
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!