how to edit local json files using node code example

Example 1: read 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);

Example 2: write json file nodejs

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

Example 3: how to edit local json files using node

const ciqlJSON = require('ciql-json')

ciqlJson
    .open("file.json")
    .set("address", {town : "", city : ""})
    .save()