I'm using JavaScript to update the contents of a JSON file, I can successfully change the desired content and parsing it works fine, but it changes other values (and outright deletes others).
Ouput:
{ name: '8Hz', phones: [ [Object], [Object], [Object] ] },
Desired Output:
{ "name": "8Hz",
"phones": [
{"name":"Salnotes Dioko","file":"7Hz Dioko","suffix":"7Hz Dioko"...},
{"name":"Salnotes Zero","file":"7Hz Zero","preferredShop":"Linsoul"},
{"name":"Timeless","file":["7Hz Timeless","7Hz Timeless (S2)"]...}
]
},
Code:
const fs=require('fs');
var oldjson=JSON.stringify(require('./phone_book.json'));
var newjson=oldjson.replace('"name":"7Hz"','"name":"8Hz"'); //Replaces "7Hz" with "8Hz"
var final=JSON.parse(newjson);
console.log(final);