changeset 134:cea81044578e

add a JSON explorer
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 25 Mar 2011 09:58:29 -0700
parents bd47021b8313
children 206a6f3144b2
files python/jsonex.py
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/jsonex.py	Fri Mar 25 09:58:29 2011 -0700
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+"""
+JSON explorer
+"""
+
+import json
+import sys
+from pprint import pprint
+
+def main(args=sys.argv[1:]):
+    data = sys.stdin.read() # read from stdin
+    obj = json.loads(data)
+
+    if args:
+        for arg in args:
+            foo = arg.split('.') # split into objects
+            # TODO: split into slice notation
+            pass # TODO
+    else:
+        print json.dumps(obj, indent=2, sort_keys=True)
+
+if __name__ == '__main__':
+    main()