JMESPath Tester

Test JMESPath queries against your JSON live, the query language of the AWS CLI and Azure CLI --query, with examples and ready-to-run commands

Result
[
  {
    "ID": "i-0123456789abcdef0",
    "Type": "t3.micro",
    "Name": "web-1"
  },
  {
    "ID": "i-0fedcba9876543210",
    "Type": "t3.large",
    "Name": "worker-1"
  },
  {
    "ID": "i-0a0b0c0d0e0f01234",
    "Type": "m7g.xlarge",
    "Name": "db-1"
  }
]
aws ec2 describe-instances --query 'Reservations[].Instances[].{ID: InstanceId, Type: InstanceType, Name: Tags[?Key=='\''Name'\''] | [0].Value}' --output json

The query is single-quoted for bash and zsh. In PowerShell, use the same single quotes; in cmd.exe, use double quotes and change any inner double quotes.

Functions

abs(number)
Absolute value.
avg(array[number])
Average of the numbers.
ceil(number)
Rounds up.
contains(array|string, any)
Whether the array has the item, or the string has the substring.
ends_with(string, suffix)
Whether the string ends with the suffix.
floor(number)
Rounds down.
join(glue, array[string])
Joins strings with the glue between them.
keys(object)
The object's keys.
length(string|array|object)
Characters, items or keys.
map(&expr, array)
Applies the expression to every item.
max(array[number|string])
The largest value.
max_by(array, &expr)
The item whose expression value is largest.
merge(object, ...)
Merges objects; later keys win.
min(array[number|string])
The smallest value.
min_by(array, &expr)
The item whose expression value is smallest.
not_null(any, ...)
The first argument that isn't null.
reverse(array|string)
Reverses the order.
sort(array[number|string])
Sorts numbers or strings.
sort_by(array, &expr)
Sorts items by the expression's value.
starts_with(string, prefix)
Whether the string starts with the prefix.
sum(array[number])
Adds the numbers.
to_array(any)
Wraps a value in an array, unless it already is one.
to_number(any)
Converts a string to a number (null if it can't).
to_string(any)
The value as a string (JSON for objects and arrays).
type(any)
number, string, boolean, array, object or null.
values(object)
The object's values.

JMESPath vs JSONPath

TaskJMESPathJSONPath
A fieldstore.name$.store.name
Every item's fielditems[].price$.items[*].price
First itemitems[0]$.items[0]
Last itemitems[-1]$.items[-1:]
Filteritems[?price > `10`]$.items[?(@.price > 10)]
Pick fields into a new objectitems[].{n: name, p: price}(not possible)
Countlength(items)$.items.length() (some engines only)
Any depth(not possible)$..price

Runs in your browser with the reference jmespath.js implementation; nothing is sent anywhere. Working with JSONPath instead (Kubernetes, Postman, many APIs)? Use the JSONPath Tester.

Was the JMESPath Tester helpful?

Get new tools in your inbox

About once a month, when new tools ship. No spam, one-click unsubscribe.

We store only your email to send these updates. Privacy

About this tool

The JMESPath Tester runs JMESPath queries against your JSON as you type. JMESPath is the query language behind the AWS CLI's --query option, the Azure CLI's --query and Ansible's json_query filter, and this tester uses the reference JavaScript implementation, so a query that works here works there. It comes with a real-shaped AWS EC2 describe-instances response and fourteen worked examples: listing instance IDs, filtering running instances, reading the Name tag, building rows for --output table, sorting by launch time and counting. Each query is turned into ready-to-run AWS CLI, Azure CLI, jp, Python and JavaScript commands, quoted correctly for the shell. Errors are explained in plain words, including the most common JMESPath mistake: "double quotes" name a field, so comparing against "running" silently matches nothing. 'Single quotes' or `backticks` are needed for values. The page also lists every built-in function and the JMESPath equivalents of common JSONPath expressions.

When to use it

  • →Building an aws ... --query expression without trial and error in the terminal
  • →Pulling a few fields out of a large Azure CLI or AWS CLI response
  • →Writing json_query filters for Ansible
  • →Learning projections, filters and multiselect hashes with live feedback

Tips

  • ◆Use 'single quotes' for string values and `backticks` for numbers and other JSON literals: [?age > `30`].
  • ◆A filter on a projection keeps the nesting; add [] at the end to flatten it into one list.
  • ◆{Name: name, Id: id} builds new objects, which is how you rename fields for --output table.
  • ◆Tags[?Key=='Name'] | [0].Value reads one tag's value; the pipe stops the projection so [0] takes the first match.
  • ◆In the AWS CLI, --query runs on the client after all pages are fetched; use --filters to reduce what's downloaded.

Frequently asked questions

What is JMESPath?

A query language for JSON with a formal specification and compliance tests, so every implementation (Python, JavaScript, Go, Java, Rust and more) gives the same answer. The AWS CLI, Azure CLI and Ansible use it to filter command output.

Why does my filter return an empty list?

Usually because of quotes. In JMESPath, "running" in double quotes is a field name, so State.Name == "running" compares against a field that doesn't exist. Write State.Name == 'running' instead. Field names are also case-sensitive.

What's the difference between JMESPath and JSONPath?

JSONPath ($.store.book[*]) is used by Kubernetes, Postman and many APIs, and implementations differ. JMESPath has one specification, can reshape data into new objects and arrays, and has functions like sort_by and length, but has no recursive descent (..).

How do I quote a --query on Windows?

In PowerShell, single quotes around the whole query work as in bash. In cmd.exe, wrap the query in double quotes and keep single quotes for string values inside it.

Is my JSON uploaded?

No. The query runs in your browser with the jmespath.js library.

Related tools

ToolNinja