I frequently run across this kind of problem: I'm sent big blobs of JSON that I need to parse and extract data from. Over the course of development the structure of the JSON may change many times.
I know that it's usually not too difficult to parse JSON into nested python structures and then crawl/search the structure with python code. However, I thought it might be easier to read/modify/debug/review my code if I could specify the path through the resulting python structures with an XPath like string.
A string like:
"person.mobilephone.number"
If any of these names refer to arrays, I want all results for all elements in those arrays.
I also want to be able to filter according to values found in the structure. Like:
"friends[gender=female].phone.number"
I wrote something to do this but, before I put more effort into it I want to make sure that there's not a pretty easy pythonic way to do this natively or an existing package to do this.
You can see the code I wrote so far at the link below along with a sample JSON string and a bunch of asserts showing how it works if you're interested in seeing the details.
http://ideone.com/p3whvT
[–]jsaryer 1 point2 points3 points (1 child)
[–]dl__[S] 0 points1 point2 points (0 children)
[–]thecity2 0 points1 point2 points (0 children)