Last active
December 28, 2015 02:59
-
-
Save jamiehannaford/7432484 to your computer and use it in GitHub Desktop.
check a project folder for dodgy JSON files and then minify
This file contains 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
import os | |
import sys | |
import json | |
rootdir = sys.argv[1] | |
for root, subFolders, files in os.walk(rootdir): | |
for file in files: | |
if (os.path.splitext(file)[1] == '.json'): | |
path = os.path.join(root,file) | |
with open(path,'r') as f: | |
try: | |
data = json.loads(f.read()) | |
print json.dumps(data, separators=(',',':')) + "\n" | |
except ValueError: | |
print path + " had a parse error.\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment