mirror of
https://github.com/samsonjs/Mojo.Ext.git
synced 2026-03-25 09:25:46 +00:00
36 lines
683 B
Python
Executable file
36 lines
683 B
Python
Executable file
#!/usr/bin/env python
|
|
|
|
"""
|
|
Convert JSON data to human-readable form.
|
|
|
|
Usage:
|
|
prettyJSON.py inputFile [outputFile]
|
|
"""
|
|
|
|
import sys
|
|
import simplejson as json
|
|
|
|
|
|
def main(args):
|
|
try:
|
|
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))
|