AZ Cli not showing correct output

Pallab Chakraborty 401 Reputation points
2021-03-07T01:07:32.41+00:00

I ran the command attached in the screenshot and it shows me three columns : DisplayName, Name and RegionalDisplayName. Now i would like to only view just two columns from the output which is Name and RegionalDisplayName. So i run the below command, but it brings me back to the prompt without displaying anything.

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

Any idea why this is happening and how can i display just two columns75111-query1.jpg

Azure Cloud Services
Azure Cloud Services
An Azure platform as a service offer that is used to deploy web and cloud applications.
674 questions
0 comments No comments
{count} votes

Accepted answer
  1. shiva patpi 13,166 Reputation points Microsoft Employee
    2021-03-07T02:48:27.05+00:00

    Hello @Anonymous ,
    This is somewhat tricky , when you are using the --query the JSON key names which you are trying to query is Case Sensitive.
    This will be the exact query:
    az account list-locations --query "[].{name:name,region:regionalDisplayName}" --output table

    Your query:
    az account list-locations --output table --query "[].{name: Name, region: RegionalDisplayName}" {See the display name it should be regionalDisplayName instead of RegionalDisplayName , see the Name it should be name}

    Basically , if you see the --query parameters
    name:name, (headername:exact name of the JSON output of az account list-locations i.e. name)
    region:regionalDisplayName (headername:exact name of the JSON output of az account list-locations i.e. regionalDisplayName)

    To validate the exact json names :

    1. Run the query az account list-locations
    2. Examine the output (Check the JSON Array values)
      Example JSON output:

    {
    "displayName": "Brazil Southeast",
    "id": "/subscriptions/subid/locations/brazilsoutheast",
    "metadata": {
    "geographyGroup": "South America",
    "latitude": "-22.90278",
    "longitude": "-43.2075",
    "pairedRegion": [
    {
    "id": "/subscriptions/subid/locations/brazilsouth",
    "name": "brazilsouth",
    "subscriptionId": null
    }
    ],
    "physicalLocation": "Rio",
    "regionCategory": "Other",
    "regionType": "Physical"
    },
    "name": "brazilsoutheast",
    "regionalDisplayName": "(South America) Brazil Southeast",
    "subscriptionId": null
    }

    So , to summarize when you are trying query JSON output, the Key names are casesensitive.

    If the above help you out in understanding , kindly make sure to "Upvote and Accept the answer". It will help all thecommunity out there.

    0 comments No comments

0 additional answers

Sort by: Most helpful