I haven't had much success with JMESPath to query the output. But I have found using jq is a little bit easier to parse the json that is returned.
For example, I need to add internal service endpoints to all the subnets within a particular virtual network. I will pass the json output to a bash array and with a for loop you can execute commands using the json key value pairs.
update_subnet() {
subnet_service_endpoints="Microsoft.EventHub Microsoft.KeyVault Microsoft.ServiceBus Microsoft.Storage"
subnet_json=$(az network vnet subnet list --subscription ${subscription_name} --resource-group ${resource_group} --vnet-name ${virtual_network} --output json)
readarray -t SUBARR < <(echo ${subnet_json} | jq -c '.[]')
for SUBNET in "${SUBARR[@]}"
do
SUBNET_NAME=$(echo "${SUBNET}" | jq -r .name)
ADDRESS_PREFIX=$(echo "${SUBNET}" | jq -r .addressPrefix)
RESOURCE_GROUP=$(echo "${SUBNET}" | jq -r .resourceGroup)
RESULT=$(az network vnet subnet update --subscription ${subscription_name} --resource-group ${resource_group} --vnet-name ${virtual_network} --name ${SUBNET_NAME} --address-prefixes ${ADDRESS_PREFIX} --service-endpoints ${subnet_service_endpoints})
if [ "$RESULT" == "" ]
then
echo "Something happened and unable to parse command"
else
echo "${RESULT}"
fi
done
}