Answers for "edit a json file in nodejs"

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

edit a json file in nodejs

//inistall ciql-json : npm i ciql-json

const ciqlJson = require("ciql-json")

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

Code answers related to "Javascript"

Browse Popular Code Answers by Language