'az webapp list is showing null values for siteConfig

I want to get list of all webapps where healhCheckPath is not nult. I tried az webapp list --query "[?not_null(siteConfig.healthCheckPath)].{Name:name, ResourceGroup:resourceGroup}" but the cli was returning empty array. I then ran the command az webapp list --query "[?name=='web_app_where_health_check_is_enabled']" and this returns one record but heathCheckPath was null but in reality health check is enabled for this specific app. Later I tried az webapp show -g <resource-group> -n <name> and this showed me the value for healthCheckPath. So the issue is with the list command. I can't use webapp show command because I want to fetch all the webapps which meet specific conditions.



Solution 1:[1]

You're using not_null, which is a Function that

Returns the first argument that does not resolve to null. This function accepts one or more arguments, and will evaluate them in order until a non null argument is encountered. If all arguments values resolve to null, then a value of null is returned.

Source: JMESPath Specification - Built-in Functions - not_null

For filtering for null values, simply use equality (==) or inequality (!=).

Comparison Operators

The following operations are supported:

  • ==, tests for equality.
  • !=, tests for inequality.
  • <, less than.
  • <=, less than or equal to.
  • >, greater than.
  • >=, greater than or equal to.

The behavior of each operation is dependent on the type of each evaluated expression.

The comparison semantics for each operator are defined below based on the >corresponding JSON type:

Equality Operators

For string/number/true/false/null types, equality is an exact match.

Your query translates to
az webapp list --query "[?siteConfig.healthCheckPath!=null].{Name:name, ResourceGroup:resourceGroup}"

EDIT:
As an addition: this query does seem to do what I understood it needs to: query web apps, returning instances with a non null value for siteConfig.healthCheckPath.

Please make sure your scripts have been deployed and no additional filters are in place. See my test-results below.

Query returning results

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1