I'm having an existing JSON file and data is like this.
[{"address":"unit f 11-13 short street, auburn, nsw 2144"},{"address":"village green brooks circuit, lidcombe, nsw 2141"}]
I want to add a new value to this JSON file. This is my method.
function saveNewAddress(
address /* :?string | void */, cb
) /* :Promise<string> */ {
return new Promise(function(resolve, reject) {
fs.appendFile('address-list.json', JSON.stringify(address), "utf8", function(err) {
if (err) throw err;
console.log("File saved.");
});
});
}
This works but it doesn't add the new value to the array. It's adding the new value to the end of the array.