Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 r"""
2 Using simplejson from the shell to validate and
3 pretty-print::
5 $ echo '{"json":"obj"}' | python -msimplejson
6 {
7 "json": "obj"
8 }
9 $ echo '{ 1.2:3.4}' | python -msimplejson
10 Expecting property name: line 1 column 2 (char 2)
12 Note that the JSON produced by this module's default settings
13 is a subset of YAML, so it may be used as a serializer for that as well.
14 """
15 import simplejson
17 #
18 # Pretty printer:
19 # curl http://mochikit.com/examples/ajax_tables/domains.json | python -msimplejson.tool
20 #
22 def main():
23 import sys
24 if len(sys.argv) == 1:
25 infile = sys.stdin
26 outfile = sys.stdout
27 elif len(sys.argv) == 2:
28 infile = open(sys.argv[1], 'rb')
29 outfile = sys.stdout
30 elif len(sys.argv) == 3:
31 infile = open(sys.argv[1], 'rb')
32 outfile = open(sys.argv[2], 'wb')
33 else:
34 raise SystemExit("%s [infile [outfile]]" % (sys.argv[0],))
35 try:
36 obj = simplejson.load(infile)
37 except ValueError, e:
38 raise SystemExit(e)
39 simplejson.dump(obj, outfile, sort_keys=True, indent=4)
40 outfile.write('\n')
43 if __name__ == '__main__':
44 main()