jmespath.py icon indicating copy to clipboard operation
jmespath.py copied to clipboard

Non-rooted expressions support

Open davidkhess opened this issue 9 years ago • 10 comments

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.

davidkhess avatar Aug 15 '16 00:08 davidkhess

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

jamesls avatar Aug 17 '16 05:08 jamesls

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.

davidkhess avatar Aug 17 '16 13:08 davidkhess

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

gholder avatar Sep 22 '16 13:09 gholder

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

EricLanduyt avatar Oct 11 '16 08:10 EricLanduyt

@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

caphrim007 avatar Aug 02 '17 03:08 caphrim007

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

sauron918 avatar Mar 21 '19 11:03 sauron918

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(""))"'
}

ogaida avatar Mar 29 '20 08:03 ogaida

Upvote!

tdrl avatar May 11 '21 19:05 tdrl

@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

chipsenkbeil avatar Jun 16 '21 15:06 chipsenkbeil

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

springcomp avatar Jun 24 '23 07:06 springcomp