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

249
Views
How to update JSON keys in place?

I would like to add a set of escaped quote around all first level keys in a JSON object.

const j = '{"a": "b", "c": "d"}';
let obj = JSON.parse(j);

Object.keys(obj).forEach(k => {
  k = `\"${k}\"`;
});

console.log(JSON.stringify(obj, null, 2));

which of course gives

{
  "a": "b",
  "c": "d"
}

as I need to do the substitution in the actual object.

But how can I update the keys in place?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This should work. Just define a new key and give it the same value as the old key, then delete the old key.

const j = '{"a": "b", "c": "d"}';
let obj = JSON.parse(j);

Object.keys(obj).forEach(k => {
 obj[`\"${k}\"`] = obj[k];
 delete obj[k];
});

console.log(JSON.stringify(obj, null, 2));

over 4 years ago · Santiago Trujillo 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!