I currently have a json file setup with the following format:
{
"OnetimeCode" : "Value"
}
And I'd like to be able to do two things:
- Append to the file (change the values in the file)
- Add New Items to the File (In the same format)
I have been searching for almost an hour trying to find either a module (for Node) or just easy sample code that would allow me to accomplish this.
I have tried using several plugins already, but rather than appending to the file, they completely rewrite it.
One of the plugins is called "jsonfile" (npm install jsonfile)
var jf = require('jsonfile'); // Requires Reading/Writing JSON
var jsonStr = WEAS_ConfigFile;
var obj = JSON.parse(jsonStr);
obj.push({OnetimeCode : WEAS_Server_NewOneTimeCode});
jf.writeFileSync(WEAS_ConfigFile, obj); // Writes object to file
But that does not seem to be working.
Any help is appreciated! But Please, keep it simple.
Also: I cannot use jQuery