Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find length of result array in Azure CLI via JMESPath?

I am trying to "explore" json results from an Azure CLI command using the --query switch (e.g. az functionapp list --query <something>), and to get started I'd like the length of the resulting array.

The Azure CLI help says nothing specific, and points to jmespath.org which does indeed show that a length function exists, however it seems to require an argument. I have no name for the argument, which is the root/outermost array returned by the list command.

It seems from jmespath.org that length(something) is what I want, but I don't know what to put in for the "something" part. What do I put here? Or am I going about this all wrong??

like image 783
basic_one Avatar asked Jan 23 '26 06:01

basic_one


2 Answers

As we know az functionapp list returns a json where the root node is an array. In order to get the length of this array we can use the following syntax:

az functionapp list --query "[] | length(@)"

like image 126
Ervin Szilagyi Avatar answered Jan 25 '26 23:01

Ervin Szilagyi


The following should also work:

az functionapp list --query "length([])"
like image 28
Persian Astroman Avatar answered Jan 25 '26 22:01

Persian Astroman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!