annotate python/jsonex.py @ 307:655a40db0977

ah, the magic switch
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 16 May 2013 11:25:10 -0700
parents cea81044578e
children e50a95358db3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
134
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 JSON explorer
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 """
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 import json
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 import sys
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 from pprint import pprint
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 def main(args=sys.argv[1:]):
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 data = sys.stdin.read() # read from stdin
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 obj = json.loads(data)
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 if args:
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 for arg in args:
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 foo = arg.split('.') # split into objects
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 # TODO: split into slice notation
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 pass # TODO
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 else:
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 print json.dumps(obj, indent=2, sort_keys=True)
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 if __name__ == '__main__':
cea81044578e add a JSON explorer
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 main()