In the last lesson, we used the --query parameter to instruct the AWS CLI to only return a subset of the information.

In this lesson, we’ll take a deeper dive to understand how it works.

JMESPath

By default, the AWS CLI returns JSON (JavaScript Object Notation) data. To filter this output, it would be useful to use a JSON-specific query language, and this is where JMESPath comes in—it is a query language for JSON.

If we pass a value to the --query parameter, the AWS CLI interprets it as a JMESPath query and applies it to the original output of the command.

JSON basics

JSON has a tree-like structure with nested objects. Each element of a JSON tree can be of one of the following data types:

  • Number
  • String
  • Boolean
  • Array
  • Object
  • NULL

The most common data types we will encounter when working with the AWS CLI are strings, key-value pairs, objects, and arrays.

Key-value pairs

Key-value pairs are heavily used in JSON and look like this:

Get hands-on with 1200+ tech skills courses.