Answers for "how to edit local json files using node"

4

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);
Posted by: Guest on April-13-2020
4

edit json via nodejs

//Using edit-json-file for NodeJS, based off the NPM documentation for edit-file-json
const editJsonFile = require("edit-json-file");
let file = editJsonFile(`${__dirname}/filename.json`);
file.set("name", "value");
file.save();
file = editJsonFile(`${__dirname}/filename.json`, {
    autosave: true
});
Posted by: Guest on October-02-2020
9

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));
Posted by: Guest on April-13-2020
0

how to edit local json files using node

const ciqlJSON = require('ciql-json')

ciqlJson
    .open("file.json")
    .set("address", {town : "", city : ""})
    .save()
Posted by: Guest on May-26-2021

Code answers related to "how to edit local json files using node"

Code answers related to "Javascript"

Browse Popular Code Answers by Language