Skip to content

Instantly share code, notes, and snippets.

@andrewbunday
Created October 11, 2011 14:29
Show Gist options
  • Save andrewbunday/1278229 to your computer and use it in GitHub Desktop.
Save andrewbunday/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.
#!/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