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?