Skip to content

Instantly share code, notes, and snippets.

@jamiehannaford
Last active December 28, 2015 02:59
Show Gist options
  • Save jamiehannaford/7432484 to your computer and use it in GitHub Desktop.
Save jamiehannaford/7432484 to your computer and use it in GitHub Desktop.
check a project folder for dodgy JSON files and then minify
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