Which Built-in Functions Are Supported by JMESPath?
The built-in functions of JMESPath support the following data types:
- number (integer and double-precision floating-point format in JSON)
- string
- boolean (true or false)
- array (an ordered sequence of values)
- object (an unordered collection of key-value pairs)
- expression (denoted by &expression)
- null
Built-in functions support different data types, as described in the following table. The special character @ in function arguments indicates that the current result is passed to the function as an input parameter.
Built-in Function |
Input Data Type |
Output Data Type |
Description |
Example |
---|---|---|---|---|
abs |
number |
number |
Returns the absolute value of the provided argument. |
|
avg |
array[number] |
number |
Returns the average of the elements in the provided array. |
Current result: [10, 15, 20] Expression: avg(@) Final result: 15 |
ceil |
number |
number |
Returns the next highest integer value by rounding up if necessary. |
Expression: ceil(`1.001`) Final result: 2 |
contains |
array|string, any |
boolean |
Returns true if the first given argument contains the second one, or otherwise returns false. |
|
ends_with |
string, string |
boolean |
Returns true if the first character string ends with the second one, or otherwise returns false. |
Current result: foobarbaz Expression: ends_with(@,'baz') Final result: true |
floor |
number |
number |
Returns the next lowest integer value by rounding down if necessary. |
Expression: floor(`1.001`) Final result: 1 |
join |
string, array[string] |
string |
Returns all of the elements from the provided character string array joined using the given string argument as a separator. |
Current result: ["a", "b"] Expression: join(',', @) Final result: "a, b" |
keys |
object |
array |
Returns an array containing the keys of the provided JSON object. Because JSON hashes are inherited and unordered, the keys associated with the provided object are also inherited and unordered. Implementations are not required to return keys in any specific order. |
|
length |
string|array|object |
number |
Returns the length of the given argument using the following type rules: 1. string: Returns the number of characters in the string. 2. array: Returns the number of elements in the array. 3. object: Returns the number of key-value pairs in the object. |
|
map |
expression->any->any, array[any] |
array[any] |
Applies the expression in the input argument to every element in the array, and returns the array of results. An element of length N will produce a return array of length N. Unlike a projection, map() will include the result of applying the expression for every element in the elements array, even if the result is null. |
|
max |
array[number]|array[string] |
number |
Returns the largest number in the provided array argument. |
|
max_by |
array, expression->number|expression->string |
any |
Returns the maximum element in an array by using the expression as a comparison key. |
Current result: [{"name": "b", "age": 30, "age_str": "30"}, {"name": "a", "age": 50, "age_str": "50"}, {"name": "c", "age": 40, "age_str": "40"}] For the preceding current result:
|
merge |
[object [, object ...]] |
object |
Accepts one or more objects as arguments, and returns a single object with subsequent objects merged. The key-value pairs of each subsequent object are added to the preceding object. This function is used to combine multiple objects into one. You can think of this as the first object being the base object, and each subsequent argument being the overrides that are applied to the base object. |
|
min |
array[number]|array[string] |
number |
Returns the smallest number in the provided array argument. |
|
min_by |
array, expression->number|expression->string |
any |
Returns the smallest element in an array using the expression as a comparison key. |
Current result: {"people": [{"name": "b", "age": 30, "age_str": "30"}, {"name": "a", "age": 50, "age_str": "50"}, {"name": "c", "age": 40, "age_str": "40"}]} For the preceding current result:
|
not_null |
[any [, any ...]] |
any |
This function accepts one or more arguments, and evaluates them in order until a non-null argument is encountered. If the values of all arguments as resolved as null, KooCLI displays an error message and outputs the original JSON result. |
|
reverse |
string|array |
string|array |
Reverses the order of the input argument. |
|
sort |
array[number]|array[string] |
array |
Accepts an array argument and returns the sorted elements as an array. The array must be a list of strings or numbers. Strings are sorted based on a dictionary. |
|
sort_by |
array, expression->number|expression->string |
- |
Sorts an array using an expression as the sort key. For each element in the array of elements, the expression is applied and the result value is used as the key for sorting the elements. sort_by follows the same sorting logic as the sort function. |
Current result: {"people": [{"name": "b", "age": 30, "age_str": "30"}, {"name": "a", "age": 50, "age_str": "50"}, {"name": "c", "age": 40, "age_str": "40"}]} For the preceding current result:
|
starts_with |
string, string |
boolean |
Returns true if the first argument starts with the second one, or otherwise returns false. |
|
sum |
array[number] |
number |
Returns the sum of the provided array argument. An empty array will produce a return value of 0. |
|
to_array |
any |
array |
array: Returns the passed value. number|string|object|boolean: Returns a one-element array containing the passed argument. |
|
to_string |
any |
string |
string: Returns the passed value. number|array|object|boolean: The JSON encoded value of the object. |
|
to_number |
any |
number |
string: Returns the parsed number. number: Returns the passed value. array|object|boolean|null: KooCLI displays an error message and outputs the original JSON result. |
|
type |
array|object|string|number|boolean|null |
string |
Returns the data type of the given argument as a string value. The return value must be one of the following:
|
|
values |
object |
array |
Returns an array of values of the provided JSON object. Because JSON hashes are inherited and unordered, the values associated with the provided object are also inherited and unordered. Implementations are not required to return values of the JSON object in any specific order. |
Current result: {"a": "first", "b": "second", "c": "third"} Expression: values(@) The final result could be as follows:
|
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot