📜  如何更新 json 文件 javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:47.495000             🧑  作者: Mango

代码示例1
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);
});