Skip to content

Instantly share code, notes, and snippets.

@dominikkaegi
Created November 8, 2019 12:47
Show Gist options
  • Select an option

  • Save dominikkaegi/611b9fc40492168fe739ea82a0e2d5c2 to your computer and use it in GitHub Desktop.

Select an option

Save dominikkaegi/611b9fc40492168fe739ea82a0e2d5c2 to your computer and use it in GitHub Desktop.
Takes a JS Object and Turns it into a JSON object and writes it into a specified file.
const fs = require('fs');
function jsObjectToJSON(filename, data) {
const formattedString =JSON.stringify(data, null, 2)
fs.writeFile(filename, formattedString, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment