Search code examples
azurejmespathazure-cli2

Az CLI query not displaying all columns properly


I have run the command

az account list locations --output table

and it displays me three columns with values in them: DisplayName, Name, RegionalDisplayName.
Now I want to view only two columns e.g Name and RegionalDisplayName. So I run the command attached in the screenshot and it shows me only one column. Any idea what is the correct way to display the two columns with the query command?

az account with JMESPath query


Solution

  • Basically, the only mistake in your query is "case sensitive names" When you are trying to query JSON output, in the --query parameter we should provide the exact name of the Json array value name.

    Your complete query will be (see the name instead of Name and the regionalDisplayName)

    az account list-locations --query "[].{name: name, region: regionalDisplayName}" --output table
    

    For more, check out the answer posted here and detailed explanation. https://learn.microsoft.com/en-us/answers/questions/302069/az-cli-not-showing-correct-output.html?childToView=302127#answer-302127