I had a need to batch edit a bunch of json files I had scraped containg my user information, each in a seperate file. There was going to be a mass update of the system so this way I could get a before and after.
Certain attributes in the export of each user will have changed in every item, and they were not relevant so when doing a bulk comparison using code compare these would show up so had to be removed.
My files were all named out.guidofuser.json and stored in folders by group so I needed to edit all of them, remove the attributes, beautify them else viewing the comparison would be hard if there was a difference.
NodeJS is wonderful at doing this stuff.
a quick npm init and npm install fs, path then this code, ripped through all my json files, edited and beautified them.
var fs = require("fs"); var path = path || require('path'); var walkSync = function (dir, filelist) { files = fs.readdirSync(dir); filelist = filelist || []; files.forEach(function (file) { if (fs.statSync(path.join(dir, file)).isDirectory()) { filelist = walkSync(path.join(dir, file), filelist); } else { var fPath = path.join(dir, file); var jsFile = require(fPath); for (var g in jsFile.groups) { delete jsFile.groups[g].modified; delete jsFile.groups[g].created; } delete jsFile.lastLogin; delete jsFile.loginCount; var json = JSON.stringify(jsFile, null, 4); fs.writeFileSync(fPath, json); filelist.push(fPath); } }); return filelist; }; var fl = walkSync("C:\\Users\\simon\\stg2", []);