jmespath / jmespath.py

JMESPath is a query language for JSON.
http://jmespath.org
MIT License
2.18k stars 181 forks source link

Non-rooted expressions support #110

Open davidkhess opened 8 years ago

davidkhess commented 8 years ago

I may just be missing it, but it doesn't seem to be possible to do the equivalent of // in XPath. I.e. find the desired expression anywhere in the supplied JSON versus from the root of it. If not, can that be made a feature request?

The use case is when you are trying to find subsets of JSON in a document whose overall structure you cannot predict in advance.

jamesls commented 8 years ago

Not currently possible, but something I think would be useful.

davidkhess commented 8 years ago

It's pretty necessary if you are working with JSON with an unknown schema but need to recognize subsets within it. I find it crops up when using JSON for metadata.

I'm not sure how many folks need this – but it's a deal breaker for that kind of situation.

gholder commented 8 years ago

Agreeing with DavidHess.
Your documentation and the project look great, but it's necessary to do the non-rooted searches.

EricLanduyt commented 8 years ago

I agree too, non-rooted expressions is the only real thing missing in JMESPath, something like a.**.b would be so nice.

caphrim007 commented 7 years ago

@jamesls would you propose a syntax for this to the JMESPath specification? even if it's not yet implemented, a proposed syntax would allow someone to produce a PR that does implement it for your review

sauron918 commented 5 years ago

It's really missing.. Is there any changes in this direction since 2016?

ogaida commented 4 years ago

for the meantime, here is a bash function i use to search values in json with jq:

function jsonValueSearch (){
    searchString=$1;
    jq -r 'paths as $path | select(getpath($path) == "'"$searchString"'") | $path | ".\(map("[\(tojson)]") | join(""))"'
}
tdrl commented 3 years ago

Upvote!

chipsenkbeil commented 3 years ago

@jamesls what are your thoughts on adopting the same recursive descent syntax as JSONPath and E4X, where .. is used to signify the descent operator. Supporting its use both at the top level (to traverse the entire JSON object) or in some portion of a definition (to traverse only the subtree).

I was going to switch from a Rust JSONPath library to the jmespath.rs library (after getting it modernized), but I need recursive descent for my use case. I serialize a lot of Rust data structures representing the vimwiki markup language into JSON. If I wanted to look up a tag, snippet of text, etc. I only know the subtree within JSON and not necessarily the full path.

image
springcomp commented 1 year ago

@chipsenkbeil We want to propose this feature to JMESPath and will include this in the next iteration for JMESPath Community.