Skip to content

Instantly share code, notes, and snippets.

Last active Dec 25, 2018
What would you like to do?
Sort entries in Sherlock data.json file
#!/usr/bin/env python3
# sort entries listed in
import re
fname = "data.json"
site_re = re.compile('(".*?\},)',re.M|re.S)
name_re = re.compile('"(.*?)": \{')
def main():
all_entries = {}
with open(fname,encoding="latin1") as fp:
data =
# add a comma to the last entry, so that the RE will include it
data = re.sub(" \}\n"," },",data)
match = site_re.findall(data)
for entry in match:
match2 = name_re.findall(entry)
site_name = match2[0]
all_entries[site_name] = entry
# case-insensitive sort
sorted_entries = sorted(list(all_entries.keys()), key=str.lower)
total = len(sorted_entries)
current = 0
for entry in sorted_entries:
current += 1
if current == total:
# do not include a comma after last entry
print( re.sub(" \},", " }", all_entries[entry]))
if "__main__" == __name__:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment