Skip to content

nodejs json

Reading JSON

import fs from 'fs';
let rawdata = JSON.parse(fs.readFileSync('./something.json'));

// Another Way
const fs = require('fs');
let rawdata = JSON.parse(fs.readFileSync('student.json'));
console.log(rawdata);

Writing JSON

fs.writeFileSync('mahFile.json', JSON.stringify(student));

Sources