json query that returns parent element and child data?
not sure why you want a query language this is pretty easy
def find_key(data,key="md5"): for k,v in data.items(): if k== key: return v if isinstance(v,dict): result = find_key(v,key) if result:return resultdict((k,find_key(v,"md5")) for k,v in json_result.items())
it's even easier if the value dict always has "_status" and "md5" as keys
dict((k,v["_status"]["md5"]) for k,v in json_result.items())
alternatively I think you could do something like
t = Tree(db)>>> dict(zip(t.execute("$."),t.execute('$..md5'))
although I dont know that it would match them up quite right ...
Here is the JSONiq code that does the job:
{| for $key in keys($document) return { $key: $document.$key._status.md5 }|}
You can execute it here with the Zorba engine.
If the 105-page manual you mention is the specification, I do not recommend reading it as a JSONiq user. I would rather advise reading tutorials or books online, which give a more gentle introduction.
Do in ObjectPath:
l = op.execute("[keys($.*), $..md5]")
you'll get:
[ [ "README.rst", "docs/conf.py" ], [ "952ee56fa6ce36c752117e79cc381df8", "6e9c7d805a1d33f0719b14fe28554ab1" ]]
then in Python:
dict(zip(l[0],l[1]))
to get:
{ 'README.rst': '952ee56fa6ce36c752117e79cc381df8', 'docs/conf.py': '6e9c7d805a1d33f0719b14fe28554ab1'}
Hope that helps. :)
PS. I'm using OPs' keys() to show how to make full query that works anywhere in the document not only when keys are in the root of document.
PS2. I might add new function so that it would look like: object([keys($.*), $..md5]). Shoot me tweet http://twitter.com/adriankal if you want that.