Created
February 1, 2017 20:59
-
-
Save richbs/bacd2841fc759b44905b6b5c38240a68 to your computer and use it in GitHub Desktop.
json_tidy.py
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 json | |
import sys | |
print sys.argv[1] | |
for root, dirs, files in os.walk(sys.argv[1]): | |
print "In", root | |
for f in files: | |
if f.endswith('.json'): | |
fh = open('/'.join([root, f])) | |
json_string = fh.read() | |
fh.close() | |
jo = json.loads(json_string) | |
new_string = json.dumps(jo, indent=2, sort_keys=True) | |
fh = open('/'.join([root, f]), 'w') | |
fh.write(new_string) | |
fh.close() | |
# print dirs, files, root |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment