node 实现对json文件的 修改
时间: 2023-06-03 07:06:44 浏览: 49
Sure, Node.js can modify JSON files using the built-in `fs` module. Here's an example of how to update a JSON file:
```
const fs = require('fs');
const path = require('path');
const filePath = path.resolve(__dirname, 'data.json'); // replace data.json with your file name and location
// read and parse the existing JSON data
const jsonData = JSON.parse(fs.readFileSync(filePath));
// make modifications to the data as needed
jsonData.someKey = 'someValue'; // replace someKey and someValue with your key-value pairs
// write the updated data back to the file
fs.writeFileSync(filePath, JSON.stringify(jsonData));
```
Note that this is just a basic example and you may need to modify it to fit your specific use case.