Search code examples
azureazure-clijmespath

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??


Solution

  • 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(@)"