question

pallab avatar image
0 Votes"
pallab asked ·

AZ Cli not showing correct output

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
query1.jpg (96.2 KiB)
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

shivapatpi-MSFT avatar image
0 Votes"
shivapatpi-MSFT answered ·

Hello @pallab ,
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.



·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.