Saturday, October 29, 2022

[SOLVED] Azure JMESPATH query for nested json

Issue

I'm trying to extract just the paths portion of the result of this AZ CLI query:

az network application-gateway show --query urlPathMaps --resource-group dev-aag --name dev-aag-gateway

I'm unsure if I should use az network application-gateway list instead

This is the result of the first query, however I'm not able to extract just the paths portion -- is this because paths is nested?

        "backendAddressPool": {
          "id": "/subscriptions/42xxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/dev-aag/providers/Microsoft.Network/applicationGateways/dev-aag-gateway/backendAddressPools/co20225020a-backend-pool",
          "resourceGroup": "dev-aag"
        },
        "backendHttpSettings": {
          "id": "/subscriptions/42xxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/dev-aag/providers/Microsoft.Network/applicationGateways/dev-aag-gateway/backendHttpSettingsCollection/dev-aag-httpsetting",
          "resourceGroup": "dev-aag"
        },
        "etag": "W/\"9f2d3xxc-2cbd-49fr-8726-432c7ef00de7\"",
        "firewallPolicy": null,
        "id": "/subscriptions/42xxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/dev-aag/providers/Microsoft.Network/applicationGateways/dev-aag-gateway/urlPathMaps/dev-aag-https-routing-rule/pathRules/co20225020a-cqvgkj9xxxxx9bcu-url",
        "loadDistributionPolicy": null,
        "name": "co20225020a-cqvgkj9xxxxx9bcu-url",
        "paths": [
          "/co20225020a/cqvgkj9xxxxx9bcu/*"
        ],
        "provisioningState": "Succeeded",
        "redirectConfiguration": null,
        "resourceGroup": "dev-aag",
        "rewriteRuleSet": null,
        "type": "Microsoft.Network/applicationGateways/urlPathMaps/pathRules"
      }

I'm trying to use grep and cut like this, but maybe something else I should be using instead:

az network application-gateway show --query urlPathMaps --resource-group dev-aag --name dev-aag-gateway | grep paths | cut -d ":" -f1-19

what should I be using to make this work?


Solution

  • az network application-gateway list -->Can used if you want to list all the application gateways under a particular subscription.
  • az network application-gateway show --> should be used if you want to pull the properties of a particular app gateway.

Refer to this articles for more information about Azure CLI application gateway cmdlets.

To pull list of paths under urlPathMaps in pathRules you need to use the below JMESPath query in the az network application-gateway show cmdlet.

 az network application-gateway show -n <AppGatewayName> -g <ResourceGroupName> --query urlPathMaps[].pathRules[].paths

I have tested this in Azure Cloud shell, it is working fine I would suggest you to validate from your end as well.

**Here is the Sample output screenshot for reference: **

enter image description here



Answered By - VenkateshDodda-MSFT
Answer Checked By - Cary Denson (WPSolving Admin)