Skip to content

Instantly share code, notes, and snippets.

@lennym
Created December 8, 2014 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lennym/46835013d0f7a8af7454 to your computer and use it in GitHub Desktop.
Save lennym/46835013d0f7a8af7454 to your computer and use it in GitHub Desktop.
json-linter.js
var fs = require('fs'),
path =require('path');
var dir = process.argv[2];
if (!dir) {
console.error('Folder path must be defined.');
console.log('Usage: node json-linter.js /path/to/test');
process.exit(1);
}
var files = fs.readdirSync(dir),
success = 0,
errors = 0;
files.forEach(function (file) {
if (file.indexOf('.json') > -1) {
var filepath = path.resolve(__dirname, dir, file);
try {
var data = require(filepath);
success++;
} catch (e) {
errors++;
console.error(filepath + ' contains invalid json');
}
}
});
console.log((success + errors) + ' files tested.');
console.log((success) + ' files passed.');
console.log((errors) + ' files failed.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment