JMESPath nested AND query (one-liner)

282 Views Asked by At

I'm working on an custom Azure Devops and trying to fill my fields through a json file. I manage to get the data one layer deep, but 2 layers seems to be challenging.

My source:

{
  "Projects": [
    {
      "Name": "Phoenix",
      "CatalogItems": {
        "Name": "w2016-its",
        "id": "49e52ffe-645d-38c2-8180-a36861969132",
        "OS": [
          "W2016-LTS-DESKTOP-MGM-Latest-cloudbase"
        ]
      },
      "Products": [
        {
          "Value": "ego",
          "Function": [
            {
              "Name": "tst",
              "Value": "tst",
              "Type": "web"
            }
          ],
          "Environment": [
            {
              "Name": "Development",
              "Value": "o"
            },
            {
              "Name": "Test",
              "Value": "t"
            }
          ],
          "Customer": [
            {
              "Name": "9446",
              "Value": "9446"
            }
          ]
        }
      ]
    }
]}

Retrieving my Project (works):

jsonpath:$.Projects[*]

Retrieving my products (works):

jsonpath:$.Projects.[?(@.Name == '{{{ProjectName}}}')].Products[*]

Retrieving my Functions (doesn't work):

jsonpath:$.Projects.[?(@.Name == '{{{ProjectName}}}') && (@.Products.Value == '{{{Application}}}')].Function[*]

All entries with {{{name}}} are variables.

I need a one-liner due to the nature Azure Devops does the queries. How can I get this nested query to work?

1

There are 1 best solutions below

0
On BEST ANSWER

I managed to get it to work with the following string:

jsonpath:$.Projects.[?(@.Name == '{{{ProjectName}}}')].Products[?(@.Value=='{{{Application}}}')].Function[*]

Hope it will help some people in the future :)