Search code examples
jmespath

How to do "object projection" filter in JMESpath, or how to filter a list?


Given the following JSON:

{
  "apps": {
    "foo": {
      "version": "1"
    },
    "bar": {
      "version": "2"
    }
  }
}

I would like to get the number of apps which have a version 2. An object projection

apps.*.version

gives a list,

[
  "1",
  "2"
]

but how to filter that list after that? I did not find any examples for that in the tutorial (since there is not property to filter against like [?version!=''], although it seems to be a quite basic use case


Solution

  • I found a solution, using this syntax it is possible to do that.

    apps.*.version | [?@=='2']