Using Node.js (v0.5.x +), you can load JSON files with the require
function; this automatically parses the file as an object. You can then add or modify keys and values as you would any other object, before stringifying it and overwriting the old file with the original and newly appended or modified data:
const fs = require("fs");
var jsonObject = require("filename.json");
jsonObject.test = 99;
jsonObject.password = "ABCDEFG";
fs.writeFile("filename.json", JSON.stringify(jsonObject), "utf8", function(err) {
if (err) throw err;
console.log("File saved.");
});