March 11, 2018
2 min read
In my office we have some large JSON files that occasionally need duplicated updates in mutliple places. Node.js makes working with these files incredibly easy with two features.
The first is that JSON files can be required as you import a module (
The second feature is not specific to Node, but is included in the
JSON.stringify() function. The third parameter of
Finally, you can write your manipulated file string back into a .json file with
const fs = require('fs');const jsonFile = require('./file.json');jsonFile.newAttribute = false;delete jsonFile.oldAttribute;fs.writeFile('newFile.json', JSON.stringify(jsonFile, null, 2));