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

Find a key wherever it is

Open ric79 opened this issue 3 years ago • 3 comments
trafficstars

Hello, is there a syntax in order to specify to look for a key in the whole data structure?

For example in JSONPath I can execute $.sections[*]..item

The double dots indicate to search 'item' at every nested level after 'sections'

Is it possible also in jmespath? Riccardo

ric79 avatar Feb 09 '22 15:02 ric79

The * is what you are looking for. Assuming your object looks like this:

{
   "A": 1,
   "B": 2,
   "C": 3
}

You can simply use

@.* 

Which will result in

[1, 2, 3]

Minitour avatar Jul 07 '22 22:07 Minitour

@ric79 unfortunately what you want to achieve is not possible using JMESPath. You have to know the input structure to query specific portions of the input.

As currently specified, I’m not sure what would be a valid use case for such a feature. 🤔

However, with the introduction of the let() function coming to JMESPath community, I definitely can see a use case where you would search for some property recursively, store that in the current lexical context and use it for downstream expressions.

springcomp avatar Aug 09 '22 11:08 springcomp

@ric79 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