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

176
Views
unable to replace a part of json value using fs javascript

this is my js code

let content019 = JSON.parse(require("fs").readFileSync("./settings.json"));
// edit or add property
content019.api.client.locations[1] = 999999999999;
//write file
fs.writeFileSync('settings.json', JSON.stringify(content019,null ,2));

i tried using content019.api.client.locations[1] but it changed the inner part to "1": "999....

this is a part of my json file

        "1": {
          "name": "Germany",
          "type": null
        },
        "2": {
          "name": "Singapore",
          "type": null
        }
      },

i want it to only change "1": { to "999999999999": {

even tried content019.api.client.locations.1, didnt work. received error unexpected number

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you have to use a string, not a number index. Since your json is invalid, I can only assume that the first part is ok, so you can try

content019.api.client.locations["1"] = 999999999999;

or maybe

content019.api.client.locations["999999"] = content019.api.client.locations["1"];
delete content019.api.client.locations["1"];
about 4 years ago · Juan Pablo Isaza Report
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!