edit-icon download-icon

Advanced filter function

Last Updated: Jan 08, 2018

Note: This feature is used for users who have many instances. If you have only one instance, ignore this feature.

Data returned upon Alibaba Cloud API calls can be presented in different formats, but it is also complex. Alibaba Cloud CLI further provides the data filter function, allowing you to filter data using filters. The filter function can help you obtain the expected value from the result, and can be used to handle results easily and quickly in use or secondary development.

Data returned upon API calls is in JSON format by default. Therefore, when using Alibaba Cloud CLI, you can use the filter function according to JSON characteristics to obtain your expected results.

Taking ECS DecribeRegions for example, run the following command, and the original JSON format output is shown as follows.

  1. aliyuncli ecs DescribeRegions --output json

filter 1

Filter 1

You can enter a key value for filtering. Run the following command, and the filter output is shown as follows.

  1. aliyuncli ecs DescribeRegions output json filter Regions

filter 2

Filter 2

If the JSON value is an array, the array subscript format is supported. Run the following command, and the filter output is shown as follows.

  1. aliyuncli ecs DescribeRegions output json filter Regions.Region[0]

filter 3

Especially, Alibaba Cloud CLI also supports ‘*’, representing the set of all results. Multiple filter results are returned as an array. Run the following command, and the filter output is shown as follows.

  1. aliyuncli ecs DescribeRegions output json filter Regions.Region[*].RegionId

filter 4

Filter 3

Filter one value from the returned data. Run the following command, and the filter output is shown as follows.

  1. aliyuncli ecs DescribeRegions output json filter Regions.Region[3].RegionId

filter 5

Thank you! We've received your feedback.