Skip to content

Instantly share code, notes, and snippets.

@R4wm
Created September 20, 2018 16:31
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 R4wm/b3ec72ae7fc52453a7f92576e8f571a7 to your computer and use it in GitHub Desktop.
Save R4wm/b3ec72ae7fc52453a7f92576e8f571a7 to your computer and use it in GitHub Desktop.
simple script to sort files in local dir, can be changed to take arg or even walk directory
#!/usr/bin/env python
import os
import json
filelist = []
for i in os.listdir('.'):
if i.endswith(".json"):
filelist.append(i)
for f in filelist:
with open(f) as l_unsorted_file:
l_unsorted_content = json.loads(l_unsorted_file.read())
with open(f, 'w') as l_sortme:
l_sortme.write(json.dumps(l_unsorted_content, indent=4, sort_keys=True))
print("Sorted {}".format(f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment