JMESPath
Query JSON with JMESPath through $jmespath(data, query): filters, projections and the built-in functions listed here.
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.
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).
ceil()
Returns the smallest integer greater than or equal to the given number. Example: ceil(total) returns 2 for 1.2.
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').
ends_with()
Returns true if the subject string ends with the given suffix, otherwise false. Example: ends_with(file, '.pdf').
floor()
Returns the largest integer less than or equal to the given number. Example: floor(total) returns 1 for 1.8.
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".
keys()
Returns an array with the keys of an object. Key order is not guaranteed.
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.
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).
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).
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.
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).
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).
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.
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).
reverse()
Reverses the order of the elements of an array, or the characters of a string. Example: reverse(items).
sort()
Sorts an array of numbers or an array of strings in ascending order; strings are compared by code point. Example: sort(tags).
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.
starts_with()
Returns true if the subject string starts with the given prefix, otherwise false. Example: starts_with(code, 'INV-').
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).
to_array()
Returns an array unchanged and wraps any other value in a one-element array.
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.
to_string()
Returns a string unchanged and converts any other value to its JSON text. Example: to_string(count) returns "2" for 2.
type()
Returns the JSON type of a value as a string: number, string, boolean, array, object or null.
values()
Returns an array with the values of an object. Order is not guaranteed.