Last active
September 30, 2018 23:54
-
-
Save pdelteil/45b8ce2c13956bd94a963681a976122c to your computer and use it in GitHub Desktop.
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
#Convert JSON data to human-readable form. | |
#Usage: | |
# prettyJSON.py inputFile [outputFile] | |
import sys | |
import simplejson as json | |
def main(args): | |
try: | |
if args[1] == '-': | |
inputFile = sys.stdin | |
else: | |
inputFile = open(args[1]) | |
input = json.load(inputFile) | |
inputFile.close() | |
except IndexError: | |
usage() | |
return False | |
if len(args) < 3: | |
print json.dumps(input, sort_keys = False, indent = 4) | |
else: | |
outputFile = open(args[2], "w") | |
json.dump(input, outputFile, sort_keys = False, indent = 4) | |
outputFile.close() | |
return True | |
def usage(): | |
print __doc__ | |
if __name__ == "__main__": | |
sys.exit(not main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment