====== JSON ======
=== Serialize JS Object to JSON===
var obj = {name: "Martin", age: 30, country: "United States"};
var json = JSON.stringify(obj);
console.log(json);
=== Read in JS object and write out JSON to file ===
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
})