Q:

write json file nodejs

const fs = require('fs');
const path = require('path');

let rawdata = fs.readFileSync(path.resolve(__dirname, 'student.json'));
let student = JSON.parse(rawdata);
console.log(student);
7
let data = JSON.stringify(student);
fs.writeFileSync('student-2.json', data);
1
const fs = require('fs');
const path = require('path');

let student = { 
    name: 'Mike',
    age: 23, 
    gender: 'Male',
    department: 'English',
    car: 'Honda' 
};
 
fs.writeFileSync(path.resolve(__dirname, 'student.json'), JSON.stringify(student));
6

New to Communities?

Join the community