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
19 if len(sys.argv) == 1:
22 elif len(sys.argv) == 2:
23 infile = open(sys.argv[1],
'r')
25 elif len(sys.argv) == 3:
26 infile = open(sys.argv[1],
'r')
27 outfile = open(sys.argv[2],
'w')
29 raise SystemExit(sys.argv[0] +
" [infile [outfile]]")
32 obj = json.load(infile,
33 object_pairs_hook=json.OrderedDict,
36 raise SystemExit(sys.exc_info()[1])
38 json.dump(obj, outfile, sort_keys=
True, indent=
' ', use_decimal=
True)
42 if __name__ ==
'__main__':