Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== JSON ====== === Serialize JS Object to JSON=== <code javascript> var obj = {name: "Martin", age: 30, country: "United States"}; var json = JSON.stringify(obj); console.log(json); </code> === Read in JS object and write out JSON to file === <code javascript> 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 }) </code> qnd/json.txt Last modified: 2021/12/16 14:09by mgupton