# HG changeset patch # User Jeff Hammel # Date 1401742186 25200 # Node ID 80c47cc35f370bfb890a0d3132311ecd8985585b # Parent d586ea538d36d74a28fb350aab7f8fdd1708b41d to method diff -r d586ea538d36 -r 80c47cc35f37 python/jsonex.py --- a/python/jsonex.py Mon Jun 02 12:40:51 2014 -0700 +++ b/python/jsonex.py Mon Jun 02 13:49:46 2014 -0700 @@ -10,6 +10,13 @@ import sys import urllib2 +def dereference(obj, key): + if obj is None: + return None + if isinstance(obj, dict): + return obj[key] + return obj[int(key)] + def main(args=sys.argv[1:]): # command line @@ -33,10 +40,13 @@ if options.object: for o in options.object: base = obj - for part in o.strip().split('.'): # split into objects - raise NotImplementedError('TODO') + for key in o.strip().split('.'): # split into objects + base = dereference(base, key) + if base is None: + break + print (json.dumps(base)) else: - print json.dumps(obj, indent=2, sort_keys=True) + print (json.dumps(obj, indent=2, sort_keys=True)) if __name__ == '__main__': main()