summaryrefslogtreecommitdiff
path: root/test/simplejson/tool.py
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2009-11-13 16:10:35 +0000
committerLukas Rytz <lukas.rytz@epfl.ch>2009-11-13 16:10:35 +0000
commit92c280f6d1116a551b805543a216eb01ab94c8cf (patch)
treefe511596d3677854b29681cfd4387da590b85515 /test/simplejson/tool.py
parent4cc65f6e0d8d3e1d26d36740dbcacb4e41c9f363 (diff)
downloadscala-92c280f6d1116a551b805543a216eb01ab94c8cf.tar.gz
scala-92c280f6d1116a551b805543a216eb01ab94c8cf.tar.bz2
scala-92c280f6d1116a551b805543a216eb01ab94c8cf.zip
updates to review script
Diffstat (limited to 'test/simplejson/tool.py')
-rw-r--r--test/simplejson/tool.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/simplejson/tool.py b/test/simplejson/tool.py
new file mode 100644
index 0000000000..90443317b2
--- /dev/null
+++ b/test/simplejson/tool.py
@@ -0,0 +1,37 @@
+r"""Command-line tool to validate and pretty-print JSON
+
+Usage::
+
+ $ echo '{"json":"obj"}' | python -m simplejson.tool
+ {
+ "json": "obj"
+ }
+ $ echo '{ 1.2:3.4}' | python -m simplejson.tool
+ Expecting property name: line 1 column 2 (char 2)
+
+"""
+import sys
+import simplejson
+
+def main():
+ if len(sys.argv) == 1:
+ infile = sys.stdin
+ outfile = sys.stdout
+ elif len(sys.argv) == 2:
+ infile = open(sys.argv[1], 'rb')
+ outfile = sys.stdout
+ elif len(sys.argv) == 3:
+ infile = open(sys.argv[1], 'rb')
+ outfile = open(sys.argv[2], 'wb')
+ else:
+ raise SystemExit(sys.argv[0] + " [infile [outfile]]")
+ try:
+ obj = simplejson.load(infile)
+ except ValueError, e:
+ raise SystemExit(e)
+ simplejson.dump(obj, outfile, sort_keys=True, indent=4)
+ outfile.write('\n')
+
+
+if __name__ == '__main__':
+ main()