How to handle JMESPath contains filter on attribute that may be null? How to handle JMESPath contains filter on attribute that may be null? shell shell

How to handle JMESPath contains filter on attribute that may be null?


Context

  • MSFT azure cloud shell console (as of 2019-11-17)
  • azure cloud shell az commands with jmespath query
  • jmespath handling of potentially-null values in a filter-expression

Use-case

  • UserJohnCDeveloper wants to run a JMESPath filter on attributes that may be null
  • how to daisy chain or pipe with the Azure az command --query clause

Solution

  • Jmespath support for pipe expressions
  • Jmespath supports passing the result of one expression to another, though use of pipe expressions. This enables queries of arbitrary complexity through chaining together of multiple sub-expressions and filters.

Example

 --query "[? publisherName!='null']|[? contains(publisherName,'ACME')]" --all


For those looking for a more general approach, use || to create an or-expression:

expression || expression

Ref jmespath.org