jmespath / jmespath.py

JMESPath is a query language for JSON.

Home Page:http://jmespath.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Find a key wherever it is

ric79 opened this issue · comments

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

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]

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