4 ms·
I've thought about this topic a lot recently. Many times I find myself working with API endpoints which return deeply nested JSON or XML "documents" which I hav
by foxhop 11y ago
I've thought about this topic a lot recently. Many times I find myself working with API endpoints which return deeply nested JSON or XML "documents" which I have no real desire to learn their schema. (AWS and ElastiSearch)
I ended up creating a Python Library to perform key lookups on these deeply nested documents. For Example:
>>> from nested_lookup import nested_lookup
>>> document = [ { 'taco' : 42 } , { 'salsa' : [ { 'burrito' : { 'taco' : 69 } } ] } ]
>>> print(nested_lookup('taco', document))
[42, 69]
Check it out here:
* https://pypi.python.org/pypi/nested-lookup https://pypi.python.org/pypi/nested-lookup
* https://github.com/russellballestrini/nested-lookup https://github.com/russellballestrini/nested-lookup
- _ZeD_ 11y agohave you heard of xpath? :)
- dunham 11y agoYou might be interested in "jq", a python program that provides an expression language for extracting and transforming json data: https://stedolan.github.io/jq/
- foxhop 11y agoI've seen jq used in various places, called from bash, ends up looking pretty unwieldy. Also briefly looking at the docs, I don't see anywhere where this nested-lookup functionality exists.
- dunham 11y agoI use jq for exploring and light massaging of json data, but for complicated tasks I just write python code. I misunderstood what your library did. jq doesn't cover that - as far as I know, there are no recursive constructs in jq.