Skip to content

Instantly share code, notes, and snippets.

@richbs
Created February 1, 2017 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richbs/bacd2841fc759b44905b6b5c38240a68 to your computer and use it in GitHub Desktop.
Save richbs/bacd2841fc759b44905b6b5c38240a68 to your computer and use it in GitHub Desktop.
json_tidy.py
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