Skip to content

Commit

Permalink
Merge pull request CloudBotIRC#216 from linuxdaemon/gonzobot+format-j…
Browse files Browse the repository at this point in the history
…son-fix

Preserve key order when formatting json files
  • Loading branch information
edwardslabs authored Nov 14, 2017
2 parents 15c6999 + 795a41a commit 4c57f30
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion format_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from pathlib import Path
import collections
import codecs
import json

Expand All @@ -11,7 +12,7 @@
for file in path.rglob("*.json"):
print(file)
with file.open(encoding='utf8') as f:
data = json.load(f)
data = json.load(f, object_pairs_hook=collections.OrderedDict)

with file.open('w', encoding='utf8') as f:
print(json.dumps(data, indent=4), file=f)
Expand Down

0 comments on commit 4c57f30

Please sign in to comment.