Created
October 11, 2011 14:29
-
-
Save andycodes00/1278229 to your computer and use it in GitHub Desktop.
I got annoyed the other day when I kept editing mission critical json based config files and had no way of knowing if the files were syntactically correct.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import json | |
import sys | |
checkedfiles={'good':[], 'bad':[]} | |
if len(sys.argv) > 1: | |
for arg in sys.argv[1:]: | |
try: | |
data = json.load(open(arg)) | |
checkedfiles['good'].append(arg) | |
except: | |
checkedfiles['bad'].append(arg) | |
print "%d OK: %s" % ( len(checkedfiles['good']) , ",".join(checkedfiles['good']) ) | |
print "%d BAD: %s" % ( len(checkedfiles['bad']) , ",".join(checkedfiles['bad']) ) | |
print "Checked total of %d files." % len(sys.argv[1:]) | |
print "---" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment