I have a Javascript object that I change by iterating through it. I want to save it as a JSON object. But how do I get the new object? If I console.log it there are two problems: First, it could be too long for the console. Second, the console removes the strings for the keys.
What is the best way to handle this?
I would like to get this JSON and copy it into another file. I've tried using fs:
var fs = require('fs');
fs.writeFile("data/datafile.json", dataObject, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
But it just writes this to the datafile.json file:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Any ideas or best practices?