1 r"""Command-line tool to validate and pretty-print JSON
5 $ echo '{"json":"obj"}' | python -m simplejson.tool
9 $ echo '{ 1.2:3.4}' | python -m simplejson.tool
10 Expecting property name: line 1 column 2 (char 2)
13 from __future__ import with_statement
15 import simplejson as json
18 if len(sys.argv) == 1:
21 elif len(sys.argv) == 2:
22 infile = open(sys.argv[1], 'r')
24 elif len(sys.argv) == 3:
25 infile = open(sys.argv[1], 'r')
26 outfile = open(sys.argv[2], 'w')
28 raise SystemExit(sys.argv[0] + " [infile [outfile]]")
31 obj = json.load(infile,
32 object_pairs_hook=json.OrderedDict,
35 raise SystemExit(sys.exc_info()[1])
37 json.dump(obj, outfile, sort_keys=True, indent=' ', use_decimal=True)
41 if __name__ == '__main__':