Answers for "javascript update json file"

0

how to update a json file javascript

const fs = require('fs');
const fileName = './file.json';
const file = require(fileName);
    
file.key = "new value";
    
fs.writeFile(fileName, JSON.stringify(file), function writeJSON(err) {
  if (err) return console.log(err);
  console.log(JSON.stringify(file));
  console.log('writing to ' + fileName);
});
Posted by: Guest on July-09-2021
0

update file json trong javascript

// read file and make object
let content = JSON.parse(fs.readFileSync('file.json', 'utf8'));
// edit or add property
content.expiry_date = 999999999999;
//write file
fs.writeFileSync('file.json', JSON.stringify(content));
Posted by: Guest on December-07-2021

Code answers related to "javascript update json file"

Code answers related to "Javascript"

Browse Popular Code Answers by Language