JMESPath tester

Input
Output

JMESPath Tester

Try JMESPath expressions against your JSON and see the result as you type. JMESPath is the query language behind the AWS CLI --query and the Azure CLI.

Example: running EC2 instances from aws ec2 describe-instances

The AWS CLI nests instances inside reservations. This expression flattens them, keeps the running ones and picks two fields, exactly as you'd pass it to aws ec2 describe-instances --query:

Input

{
  "Reservations": [
    {
      "Instances": [
        {
          "InstanceId": "i-0a1b2c3d",
          "InstanceType": "t3.micro",
          "State": {
            "Name": "running"
          }
        },
        {
          "InstanceId": "i-0e4f5a6b",
          "InstanceType": "t3.large",
          "State": {
            "Name": "stopped"
          }
        }
      ]
    },
    {
      "Instances": [
        {
          "InstanceId": "i-0c7d8e9f",
          "InstanceType": "m7g.large",
          "State": {
            "Name": "running"
          }
        }
      ]
    }
  ]
}

Expression

Reservations[].Instances[?State.Name=='running'].[InstanceId, InstanceType][]

Output

[
  [
    "i-0a1b2c3d",
    "t3.micro"
  ],
  [
    "i-0c7d8e9f",
    "m7g.large"
  ]
]

How do I use the JMESPath tester?

  1. Paste JSON, for example AWS CLI output.
  2. Type an expression such as items[?price > `500`].name.
  3. Copy the result or the expression.

What does the JMESPath tester do?

  • Filters, projections and multi-select
  • Functions like sort_by, max_by, length and join
  • Same syntax as aws --query

When to use the JMESPath tester

JMESPath is a query language for JSON with a written specification, so an expression gives the same result in the AWS CLI and Azure CLI --query option, Ansible's json_query filter and the JMESPath libraries for Python, JavaScript, Go, Java and other languages.

It reads left to right: a name picks a field, [] flattens a list, [?State.Name=='running'] filters it, [a, b] or {id: a} picks several fields, and | starts a new expression on the result. Functions such as sort_by, max_by, length, contains and join cover most of the rest.

Trying expressions here is quicker than re-running a slow CLI call each time: run the command once with --output json, paste the result, and refine the expression until the output is right.

Frequently asked questions

When do I use backticks and when quotes?
Backticks wrap a JSON literal such as a number: price > `500`. Single quotes wrap a plain string: name == 'Mouse'. Double quotes are for field names with special characters, like "content-type".
Why does my filter return an empty list or null?
A filter on a list of lists needs flattening first: Reservations[].Instances[] gives one list of instances. Field names are case-sensitive, and a string never equals a number, so write `500` to compare with a number and '500' for a string.
Should I use JMESPath or jq?
JMESPath is built into the AWS and Azure CLIs and is simpler to read. jq can also build and change data, with variables, reduce and functions of your own; Bracely has a jq tool for that.
Is this the same as the AWS CLI --query?
Yes, the AWS CLI uses JMESPath, so an expression that works here works there.
Is my data uploaded?
No. Bracely runs entirely in your browser, so nothing you paste or open leaves your device.

More JSON tools

Bracely has 108 JSON tools in one page. Related ones:

Runs entirely in your browser. Nothing you paste is uploaded. Made by Saurabh Pagrut · About · Privacy policy
Last updated · Version 6.7 · Changelog
Saurabh Pagrut on GitHub · LinkedIn · X · YouTube · Instagram