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')

const data = require('./data.js');

var json = JSON.stringify(data);

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