qnd:json

This is an old revision of the document!


JSON

Convert JS Object to JSON text

var obj = {name: "Martin", age: 30, country: "United States"};
    
var json = JSON.stringify(obj);
    
console.log(json);

Write JSON to file

const fs = require('fs')

fs.writeFile('/Users/joe/test.txt', json, err => {
  if (err) {
    console.error(err)
    return
  }
  //file written successfully
})
  • qnd/json.1639601221.txt.gz
  • Last modified: 2021/12/15 20:47
  • by mgupton