Skip to the tool
GigaJSON JMESPath Playground
All tools
Format and check
View and query
Convert
JSON to code
Encode and decode
Sample files
Guides Open GigaJSON

JMESPath Playground

Build and test --query expressions for the AWS CLI, Azure CLI and Ansible. Runs in your browser.

Write a JMESPath expression and see its result on your JSON as you type. JMESPath is the language of the --query option in the AWS CLI and the Azure CLI, so you can get an expression right on a saved response before you run the command again. To compare with JSONPath on the same data, use the JSONPath Tester.

How to use it

  1. Start from an example, such as aws ec2 describe-instances, or paste your own JSON with Edit or Open file.
  2. Pick an "I want to" pattern, click a line of the data to put its path in the query, or type: suggestions come from the data.
  3. Read the result as JSON, a table or text. Explain shows each step, and a hint offers a fix when a query fails or finds nothing.
  4. Copy for… gives the query as an AWS CLI, Azure CLI, Ansible or Python command.

Read more: n8n $json expressions explained: paths, items and $jmespath · jq vs JSONPath vs JMESPath: the same 8 tasks in all three

Private, and made for big files

This tool runs in your browser, in a background worker: nothing you paste or open is uploaded, and nothing is kept after you leave. JSON and XML input can be up to 1 GB, depending on available memory. Processing runs in a background worker; large analyses can take a minute or more. Already loaded features keep working if your connection drops. Loading another tool or jq for the first time needs a connection. When one tool isn't enough, GigaJSON opens your data with a tree, a table, JSONPath/JMESPath/jq queries, transforms, diff and history.

JMESPath syntax, with examples

Each example runs on the aws ec2 describe-instances data in the playground, and shows its real result. Try it loads the example above, so you can change it and watch the result.

field Take a field

JMESPath
Reservations[0].ReservationId
Result
"r-0a1b2c3d4e5f60718"

a.b A field inside a field

JMESPath
Reservations[0].Instances[0].State.Name
Result
"running"

[0] [-1] One item by position. -1 is the last

JMESPath
Reservations[0].Instances[-1].InstanceId
Result
"i-07c1d8e2a4b6f9e02"

[start:stop] A slice of a list

JMESPath
Reservations[0].Instances[:1].InstanceId
Result
[
  "i-0f3a9c2e7b1d45e01"
]

[*] Every item. What follows runs on each one (a projection)

JMESPath
Reservations[*].ReservationId
Result
[
  "r-0a1b2c3d4e5f60718",
  "r-09f8e7d6c5b4a3921"
]

[] Every item, with nested lists flattened into one list

JMESPath
Reservations[].Instances[].InstanceId
Result
[
  "i-0f3a9c2e7b1d45e01",
  "i-07c1d8e2a4b6f9e02",
  "i-0b5e2f7a9c3d18e03"
]

[?condition] Keep the items where the condition is true

JMESPath
Reservations[].Instances[?State.Name == 'running'][].InstanceId
Result
[
  "i-0f3a9c2e7b1d45e01",
  "i-0b5e2f7a9c3d18e03"
]

== != < <= > >= Compare. Numbers go in backticks

JMESPath
Reservations[].Instances[?CpuOptions.CoreCount > `1`][].InstanceId
Result
[
  "i-0b5e2f7a9c3d18e03"
]

&& || ! And, or, not

JMESPath
Reservations[].Instances[?State.Name == 'running' && InstanceType != 't3.micro'][].InstanceId
Result
[
  "i-0b5e2f7a9c3d18e03"
]

{name: expr} Build an object for each item

JMESPath
Reservations[].Instances[].{id: InstanceId, state: State.Name}
Result
[
  {
    "id": "i-0f3a9c2e7b1d45e01",
    "state": "running"
  },
  {
    "id": "i-07c1d8e2a4b6f9e02",
  …

[expr, expr] Build a list for each item

JMESPath
Reservations[].Instances[].[InstanceId, InstanceType]
Result
[["i-0f3a9c2e7b1d45e01","t3.micro"],["i-07c1d8e2a4b6f9e02","m5.large"],["i-0b5e2f7a9c3d18e03","c6i.xlarge"]]

| Pipe: end the projection and work on the whole result

JMESPath
Reservations[].Instances[].InstanceId | [0]
Result
"i-0f3a9c2e7b1d45e01"

@ The current value

JMESPath
Reservations[].Instances[].InstanceType | sort(@)
Result
[
  "c6i.xlarge",
  "m5.large",
  "t3.micro"
]

'text' `json` A string, and a JSON literal such as a number or true

JMESPath
length(Reservations[].Instances[?CpuOptions.ThreadsPerCore == `2` && State.Name == 'running'][])
Result
2

JMESPath functions

Functions take arguments in parentheses. The ones that sort or pick by a field (sort_by, max_by, min_by, map) take it with & in front.

length() How many items, keys or characters

JMESPath
length(Reservations[].Instances[])
Result
3

sort_by() Sort a list by a field (note the &)

JMESPath
sort_by(Reservations[].Instances[], &LaunchTime)[].InstanceId
Result
[
  "i-07c1d8e2a4b6f9e02",
  "i-0f3a9c2e7b1d45e01",
  "i-0b5e2f7a9c3d18e03"
]

max_by() min_by() The item with the largest or smallest value

JMESPath
max_by(Reservations[].Instances[], &CpuOptions.CoreCount).InstanceId
Result
"i-0b5e2f7a9c3d18e03"

contains() A string contains text, or a list contains a value

JMESPath
Reservations[].Instances[?contains(InstanceType, 'large')][].InstanceId
Result
[
  "i-07c1d8e2a4b6f9e02",
  "i-0b5e2f7a9c3d18e03"
]

starts_with() ends_with() A string starts or ends with text

JMESPath
Reservations[].Instances[?starts_with(InstanceType, 't3')][].InstanceId
Result
[
  "i-0f3a9c2e7b1d45e01"
]

join() Join strings into one

JMESPath
join(', ', Reservations[].Instances[].InstanceType)
Result
"t3.micro, m5.large, c6i.xlarge"

sum() avg() Add up or average numbers

JMESPath
sum(Reservations[].Instances[].CpuOptions.CoreCount)
Result
4

keys() values() The keys or values of an object

JMESPath
keys(Reservations[0].Instances[0])
Result
["InstanceId","InstanceType","State","PrivateIpAddress","LaunchTime","CpuOptions","Tags"]

map() Apply an expression to each item

JMESPath
map(&InstanceType, Reservations[].Instances[])
Result
[
  "t3.micro",
  "m5.large",
  "c6i.xlarge"
]

to_string() to_number() Convert a value

JMESPath
Reservations[].Instances[].to_string(CpuOptions.CoreCount)
Result
[
  "1",
  "1",
  "2"
]

AWS CLI and Azure CLI --query recipes

The AWS CLI and the Azure CLI filter their output with the same JMESPath. Each recipe is a full command, quoted for bash and zsh, with its result on the example data. In PowerShell, put the query in single quotes and double any single quotes inside it; Copy for… in the playground does this for you.

The IDs of running instances

AWS CLI · bash
aws ec2 describe-instances --query "Reservations[].Instances[?State.Name=='running'][].InstanceId" --output json
Result
[
  "i-0f3a9c2e7b1d45e01",
  "i-0b5e2f7a9c3d18e03"
]

Add --output text to get the IDs on one line, ready for another command.

Each instance's Name tag

AWS CLI · bash
aws ec2 describe-instances --query "Reservations[].Instances[].Tags[?Key=='Name'].Value | []" --output json
Result
[
  "web-1",
  "batch-worker",
  "api-1"
]

Tags are a list of Key/Value pairs, so the tag is found with a filter. | [] turns the list of lists into one list.

Instance ID next to its Name tag

AWS CLI · bash
aws ec2 describe-instances --query "Reservations[].Instances[].{id: InstanceId, name: Tags[?Key=='Name'] | [0].Value}" --output json
Result
[
  {
    "id": "i-0f3a9c2e7b1d45e01",
    "name": "web-1"
  },
  {
    "id": "i-07c1d8e2a4b6f9e02",
  …

The most recently launched instance

AWS CLI · bash
aws ec2 describe-instances --query "sort_by(Reservations[].Instances[], &LaunchTime)[-1].InstanceId" --output json
Result
"i-0b5e2f7a9c3d18e03"

LaunchTime is an ISO date, so sorting the text sorts by time.

How many instances are running

AWS CLI · bash
aws ec2 describe-instances --query "length(Reservations[].Instances[?State.Name=='running'][])" --output json
Result
2

Instances of one family

AWS CLI · bash
aws ec2 describe-instances --query "Reservations[].Instances[?starts_with(InstanceType, 't3')][].InstanceId" --output json
Result
[
  "i-0f3a9c2e7b1d45e01"
]

Buckets whose names start with logs

AWS CLI · bash
aws s3api list-buckets --query "Buckets[?starts_with(Name, 'logs')].Name" --output json
Result
[
  "logs-cloudtrail-eu",
  "logs-alb-prod"
]

The newest bucket

AWS CLI · bash
aws s3api list-buckets --query "sort_by(Buckets, &CreationDate)[-1].Name" --output json
Result
"prod-backups"

Lambda functions on Python 3.12

AWS CLI · bash
aws lambda list-functions --query "Functions[?Runtime=='python3.12'].FunctionName" --output json
Result
[
  "nightly-report",
  "webhook-handler"
]

Total memory of all Lambda functions

AWS CLI · bash
aws lambda list-functions --query "sum(Functions[].MemorySize)" --output json
Result
1792

Azure VMs in one region

Azure CLI · bash
az vm list --show-details --query "[?location=='westeurope'].name" --output json
Result
[
  "web-vm-01",
  "build-agent"
]

Running Azure VMs with their size

Azure CLI · bash
az vm list --show-details --query "[?powerState=='VM running'].{name: name, size: hardwareProfile.vmSize}" --output json
Result
[{"name":"web-vm-01","size":"Standard_B2s"},{"name":"db-vm-01","size":"Standard_D4s_v5"}]

Common JMESPath errors and how to fix them

The messages come from the JMESPath this page runs and, for the AWS CLI, from Python's jmespath library, which the AWS CLI uses. The playground also spots these mistakes as you type and offers the fix.

Invalid token (Number), or Parse error … token "1" (NUMBER)

JMESPath writes numbers in backticks. Without them, 1 isn't a value the parser accepts at that point.

JMESPath
Wrong:
Reservations[].Instances[?CpuOptions.CoreCount > 1][].InstanceId
Right:
Reservations[].Instances[?CpuOptions.CoreCount > `1`][].InstanceId
This playground
Invalid token (Number): "1"
AWS CLI
invalid token: Parse error at column 49, token "1" (NUMBER)

Nothing found with "double quotes"

In JMESPath, "running" in double quotes is a field called running, not text. The comparison never matches, so the result is empty. Text goes in single quotes.

JMESPath
Wrong:
Reservations[].Instances[?State.Name=="running"][].InstanceId
Right:
Reservations[].Instances[?State.Name=='running'][].InstanceId
This playground
No error. The result is []

Unknown function: lenght()

Function names are spelled exactly, with underscores: sort_by, max_by, starts_with.

JMESPath
Wrong:
lenght(Reservations[].Instances[])
Right:
length(Reservations[].Instances[])
This playground
Unknown function: lenght()
AWS CLI
Unknown function: lenght()

Expected Rbracket, or Incomplete expression

A [ is never closed. Every filter ends with ].

JMESPath
Wrong:
Reservations[].Instances[?State.Name=='running'.InstanceId
Right:
Reservations[].Instances[?State.Name=='running'][].InstanceId
This playground
Expected Rbracket, got: EOF
AWS CLI
Invalid jmespath expression: Incomplete expression

An empty list from a field name in the wrong case

Field names are case-sensitive, and a field that isn't there gives null, so nothing is reported. AWS names start with a capital letter.

JMESPath
Wrong:
Reservations[].Instances[].instanceId
Right:
Reservations[].Instances[].InstanceId
This playground
No error. The result is []

sort_by() expected argument 2 to be type expression

sort_by, max_by, min_by and map need an expression reference: the field with & in front.

JMESPath
Wrong:
sort_by(Reservations[].Instances[], LaunchTime)[].InstanceId
Right:
sort_by(Reservations[].Instances[], &LaunchTime)[].InstanceId
This playground
TypeError: sort_by() expected argument 2 to be type expression but received type null instead.
AWS CLI
In function sort_by(), invalid type for value: None, expected one of: ['expref'], received: "null"

'>' not supported between instances of 'int' and 'str'

'1' in single quotes is text. The browser's JMESPath compares it anyway, but the AWS CLI stops with this error. Compare numbers with 1.

JMESPath
Wrong:
Reservations[].Instances[?CpuOptions.CoreCount > '1'][].InstanceId
Right:
Reservations[].Instances[?CpuOptions.CoreCount > `1`][].InstanceId
This playground
No error. The result is ["i-0b5e2f7a9c3d18e03"]
AWS CLI
TypeError: '>' not supported between instances of 'int' and 'str'

A query with backticks breaks in bash

Inside double quotes, bash runs `…` as a command, so a number in backticks disappears before the AWS CLI sees the query. Put the whole query in single quotes. Copy for… picks the right quotes for you.

AWS CLI · bash
aws ec2 describe-instances --query 'Reservations[].Instances[?CpuOptions.CoreCount > `1`][].InstanceId'

Questions

How do I use JMESPath with the AWS CLI?

Add --query with the expression to any command, in single quotes in bash: aws ec2 describe-instances --query 'Reservations[].Instances[].InstanceId'. The CLI runs the query on the JSON before printing it, and --output text prints the values on one line. Test the query here first on a saved response.

How do I filter by a tag in the AWS CLI?

Tags are a list of Key and Value pairs, so filter that list: Reservations[].Instances[].Tags[?Key=='Name'].Value | []. To keep the instances that have a tag, filter the instances: Reservations[].Instances[?Tags[?Key=='env' && Value=='prod']][].InstanceId.

Why does my --query return an empty list?

Check for text in "double quotes" (JMESPath reads it as a field name, use 'single quotes'), a field name in the wrong case (InstanceId, not instanceId), or a filter that matches nothing. The playground spots the first two and offers the fix.

What is the difference between [] and [*]?

Both take every item and run what follows on each. [] also flattens nested lists into one list, so Reservations[].Instances[] gives one list of instances, while Reservations[*].Instances[*] gives a list per reservation.

What does a JMESPath expression look like?

items[0].name picks one value. items[*].name takes a field from every item. items[?price > `10`] filters, with literals in backticks. Functions such as length(), sort_by() and join() reshape the result, and | passes it to the next expression.

What is the difference between JMESPath and JSONPath?

JSONPath selects values by their path. JMESPath can also build new objects and lists from them, like {id: id, name: name}, and it has a written specification, so implementations agree on the result.

Is it the same JMESPath as the AWS CLI?

Yes. It uses the jmespath JavaScript library, which follows the same specification as the Python library inside the AWS CLI, so an expression gives the same result in both.

Is my data uploaded?

No. The tool runs in your browser, in a background worker. Nothing you paste or open goes to a server, and nothing is kept after you leave the page.

All tools