Back to index

python3.2  3.2.2
Functions
json.tool Namespace Reference

Functions

def main

Function Documentation

def json.tool.main ( void  )

Definition at line 16 of file tool.py.

00016 
00017 def main():
00018     if len(sys.argv) == 1:
00019         infile = sys.stdin
00020         outfile = sys.stdout
00021     elif len(sys.argv) == 2:
00022         infile = open(sys.argv[1], 'rb')
00023         outfile = sys.stdout
00024     elif len(sys.argv) == 3:
00025         infile = open(sys.argv[1], 'rb')
00026         outfile = open(sys.argv[2], 'wb')
00027     else:
00028         raise SystemExit(sys.argv[0] + " [infile [outfile]]")
00029     try:
00030         obj = json.load(infile)
00031     except ValueError as e:
00032         raise SystemExit(e)
00033     json.dump(obj, outfile, sort_keys=True, indent=4)
00034     outfile.write('\n')
00035 

Here is the call graph for this function: