On this page
Sommatic Docs
Open portal

JMESPath

Query JSON with JMESPath through $jmespath(data, query): filters, projections and the built-in functions listed here.

View as Markdown
Open in

Version 0.16.0 Apache-2.0 Official documentation

The first argument is the data, the second the query string:

{{ $jmespath($json, 'items[?status==`open`].id') }}

Functions

abs()

Returns the absolute value of a number. A non-number argument raises an invalid-type error.

{{ $jmespath($json.body, 'abs(`-4.5`)') }}
Result number
4.5

avg()

Returns the average of an array of numbers, or null for an empty array. Every element must be a number. Example: avg(items[*].price).

{{ $jmespath($json.body, 'avg(items[*].price)') }}
Result number
13.166666666666666

ceil()

Returns the smallest integer greater than or equal to the given number. Example: ceil(total) returns 2 for 1.2.

{{ $jmespath($json.body, 'ceil(items[0].price)') }}
Result number
11

contains()

Returns true if an array contains an element equal to the search value, or if a string contains the search string as a substring. Example: contains(tags, 'urgent').

{{ $jmespath($json.body, 'contains(tags, `"web"`)') }}
Result boolean
true
{{ $jmespath($json.body, 'contains(email, `"@example.com"`)') }}
Result boolean
true

ends_with()

Returns true if the subject string ends with the given suffix, otherwise false. Example: ends_with(file, '.pdf').

{{ $jmespath($json.body, 'ends_with(email, `"example.com"`)') }}
Result boolean
true

floor()

Returns the largest integer less than or equal to the given number. Example: floor(total) returns 1 for 1.8.

{{ $jmespath($json.body, 'floor(items[0].price)') }}
Result number
10

join()

Concatenates an array of strings, placing the glue string between each element; the glue is the first argument. Every element must be a string. Example: join(', ', tags) returns "a, b".

{{ $jmespath($json.body, 'join(`", "`, items[*].sku)') }}
Result string
"A-100, B-200, C-300"

keys()

Returns an array with the keys of an object. Key order is not guaranteed.

{{ $jmespath($json.body, 'keys(customer)') }}
Result list
["name","segment"]

length()

Returns the number of code points in a string, the number of elements in an array, or the number of key-value pairs in an object. Any other type raises an invalid-type error.

{{ $jmespath($json.body, 'length(items)') }}
Result number
3
{{ $jmespath($json.body, 'length(order_id)') }}
Result number
8

map()

Applies an expression reference to every element of an array and returns the results. Unlike a projection, null results are kept, so the output has the same length as the input. Example: map(&name, people).

{{ $jmespath($json.body, 'map(&qty, items)') }}
Result list
[2,0,1]

max()

Returns the highest value in an array of numbers or an array of strings, or null for an empty array. Example: max(items[*].price).

{{ $jmespath($json.body, 'max(items[*].price)') }}
Result number
25

max_by()

Returns the element of an array for which the expression reference yields the highest value; the expression must return a number or a string. Example: max_by(people, &age).name.

{{ $jmespath($json.body, 'max_by(items, &price).sku') }}
Result string
"C-300"

merge()

Merges zero or more objects into a single object. When several objects share a key, the value from the last one wins. Example: merge(defaults, overrides).

{{ $jmespath($json.body, 'merge(customer, `{"vip": true}`)') }}
Result object
{"name":"Ana Pérez","segment":"gold","vip":true}

min()

Returns the lowest value in an array of numbers or an array of strings, or null for an empty array. Example: min(items[*].price).

{{ $jmespath($json.body, 'min(items[*].qty)') }}
Result number
0

min_by()

Returns the element of an array for which the expression reference yields the lowest value; the expression must return a number or a string. Example: min_by(people, &age).name.

{{ $jmespath($json.body, 'min_by(items, &price).sku') }}
Result string
"B-200"

not_null()

Evaluates its arguments in order and returns the first one that is not null, or null if all of them are. Empty arrays and other falsy values count as not null. Example: not_null(nickname, name).

{{ $jmespath($json.body, 'not_null(shipping, customer.segment)') }}
Result string
"gold"

reverse()

Reverses the order of the elements of an array, or the characters of a string. Example: reverse(items).

{{ $jmespath($json.body, 'reverse(items[*].sku)') }}
Result list
["C-300","B-200","A-100"]

sort()

Sorts an array of numbers or an array of strings in ascending order; strings are compared by code point. Example: sort(tags).

{{ $jmespath($json.body, 'sort(tags)') }}
Result list
["new","new","web"]

sort_by()

Sorts an array by the value the expression reference returns for each element, which must be a number or a string. Example: sort_by(people, &age)[*].name.

{{ $jmespath($json.body, 'sort_by(items, &price)[*].sku') }}
Result list
["B-200","A-100","C-300"]

starts_with()

Returns true if the subject string starts with the given prefix, otherwise false. Example: starts_with(code, 'INV-').

{{ $jmespath($json.body, 'starts_with(order_id, `"ord_"`)') }}
Result boolean
true

sum()

Returns the sum of an array of numbers, or 0 for an empty array. Every element must be a number. Example: sum(items[*].amount).

{{ $jmespath($json.body, 'sum(items[*].qty)') }}
Result number
3

to_array()

Returns an array unchanged and wraps any other value in a one-element array.

{{ $jmespath($json.body, 'to_array(order_id)') }}
Result list
["ord_1042"]

to_number()

Returns a number unchanged and parses a string that holds a valid JSON number; any other value, including a string that is not a number, yields null.

{{ $jmespath($json.body, 'to_number(`"42.5"`)') }}
Result number
42.5

to_string()

Returns a string unchanged and converts any other value to its JSON text. Example: to_string(count) returns "2" for 2.

{{ $jmespath($json.body, 'to_string(items[0].qty)') }}
Result string
"2"

type()

Returns the JSON type of a value as a string: number, string, boolean, array, object or null.

{{ $jmespath($json.body, 'type(items)') }}
Result string
"array"

values()

Returns an array with the values of an object. Order is not guaranteed.

{{ $jmespath($json.body, 'values(customer)') }}
Result list
["Ana Pérez","gold"]

Install agent tools

Give your coding agent the official Sommatic AI docs: skills, the docs MCP server and Markdown pages, so it never has to scrape the site.

Skills only. They do not update by themselves; run it again to refresh.

npx skills add https://docs.sommatic.ai
How agents read these docs