1const fs = require('fs');
2const path = require('path');
3
4let rawdata = fs.readFileSync(path.resolve(__dirname, 'student.json'));
5let student = JSON.parse(rawdata);
6console.log(student);
1//Using edit-json-file for NodeJS, based off the NPM documentation for edit-file-json
2const editJsonFile = require("edit-json-file");
3let file = editJsonFile(`${__dirname}/filename.json`);
4file.set("name", "value");
5file.save();
6file = editJsonFile(`${__dirname}/filename.json`, {
7 autosave: true
8});
1const fs = require('fs');
2const path = require('path');
3
4let student = {
5 name: 'Mike',
6 age: 23,
7 gender: 'Male',
8 department: 'English',
9 car: 'Honda'
10};
11
12fs.writeFileSync(path.resolve(__dirname, 'student.json'), JSON.stringify(student));
13
1//inistall ciql-json : npm i ciql-json
2
3const ciqlJson = require("ciql-json")
4
5ciqlJson
6 .open("file.json")
7 .set("address", {town : "", city : ""})
8 .save()