Home > Back-end >  How to get only the priority from the entire JSON object in Bash Script?
How to get only the priority from the entire JSON object in Bash Script?

Time:12-20

I am trying to get the highest priority used for the application gateway rules. I can get the rules using the below command:

az network application-gateway rule list -g $resource_group_name --gateway-name $app_gateway_name

How can we retrieve the priority from that data in a bash script?

CodePudding user response:

try to use jq tool, it requires installation, but it allows to manipulate JSON structures and even modify it.

I see that 'az' command also support JMESpath. So you can filter exactly what you need.

--query JMESPath query string. See http://jmespath.org/ for more information and examples.

I didn't know what is output structure. So as example command can be look like this:

az network application-gateway rule list \
    -g $resource_group_name \
    --gateway-name $app_gateway_name \
    --query '[].priority | sort(@) | [0]'
  • Related