如何使用nodejs更新json文件数组值(特定值)。
json file:
{
"EmailSubjects": {
"RegistrationMailSubject": "New User Registration",
"ApprovedMailSubject": "new user Approval ",
"RejectedMailSubject": "new user Your ",
"ForgetPasswordSubject": "password recovery"
}
}
在这个电子邮件主题中我只想更新registrationmailsubject值。 如何实现这一目标..
答案 0 :(得分:0)
EmailSubjects.RegistrationMailSubject = "my new value"
答案 1 :(得分:0)
let data = require('./path/to/file.json');
data.EmailSubjects.RegistrationMailSubject = 'New Text';
// if you want to persist the data
let fs = require('fs');
fs.writeFileSync('./path/to/file.json', JSON.stringify(data));