var obj = {name: "Martin", age: 30, country: "United States"}; var json = JSON.stringify(obj); console.log(json);
const fs = require('fs') // Read JS object from file const data = require('./data.js'); // Convert object defined in data.js var json = JSON.stringify(obj_from_data); fs.writeFile('/tmp/data.json', json, err => { if (err) { console.error(err) return } //file written successfully })