Created
December 29, 2017 23:07
-
-
Save KyleJamesWalker/071158233fc82eaf0d8a1f9e273c716c to your computer and use it in GitHub Desktop.
Print a JSON file with color!
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 json | |
from pygments import highlight, lexers, formatters | |
def pretty_json_file(fn): | |
print(highlight( | |
json.dumps(json.load(open(fn)), sort_keys=True, indent=2), | |
lexers.JsonLexer(), | |
formatters.TerminalFormatter(), | |
)) | |
pretty_json_file('example.json') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment