// 假设你的JSON对象保存在一个名为data.json的文件中 const fs = require("fs"); // 读取JSON文件 fs.readFile("./en.json", "utf8", (err, data) => { if (err) { console.error(err); return; } // 解析JSON let jsonData = JSON.parse(data); // 遍历JSON对象中的每个值,并将其内容首字母大写 function capitalizeFirstLetter(obj) { if (typeof obj === "object") { for (let key in obj) { obj[key] = capitalizeFirstLetter(obj[key]); } return obj; } else if (typeof obj === "string") { return obj.charAt(0).toUpperCase() + obj.slice(1); } else { return obj; } } // 将首字母大写后的JSON对象转换回字符串并写入文件 fs.writeFile( "./ens.json", JSON.stringify(capitalizeFirstLetter(jsonData), null, 4), err => { if (err) { console.error(err); return; } console.log("文件已保存!"); } ); });