# JMESPath custom functions

```json metadata
{
  "schema_version": 2,
  "title": "JMESPath custom functions",
  "description": "JMESPath custom function reference",
  "categories": ["docs","integrate","rs","rdi"],
  "group": "di",
  "tableOfContents": {"sections":[]}

,
  "codeExamples": []
}
```


See also the [JMESPath functions proposal](https://jmespath.org/proposals/functions.html)
for a full description of the function syntax and a list of built-in functions.

| Function             | Description                                                                                                                         | Example                                                                                                                                                                                                  | Comments                                                                                                                                                         |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `base64_decode`      | Decodes a base64(RFC 4648) encoded string                                                                                           | Input: `{"encoded": "SGVsbG8gV29ybGQh"}` <br /> Expression: `base64_decode(encoded)` <br /> Output: `Hello World!`                                                                                       |                                                                                                                                                                  |
| `capitalize`         | Capitalizes all the words in the string                                                                                             | Input: `{"name": "john doe"}` <br /> Expression: `capitalize(name)` <br /> Output: `John Doe`                                                                                                            |                                                                                                                                                                  |
| `concat`             | Concatenates an array of variables or literals                                                                                      | Input: `{"fname": "john", "lname": "doe"}` <br /> Expression: `concat([fname, ' ' ,lname])` <br /> Output: `john doe`                                                                                    | This is equivalent to the more verbose built-in expression: `' '.join([fname,lname])`                                                                            |
| `filter_entries`     | Filters entries in a dictionary (object) using the given JMESPath predicate                                                         | Input: `{ "name": "John", "age": 30, "country": "US", "score": 15}` <br /> Expression: `` filter_entries(@, `key == 'name' \|\| key == 'age'`)``<br /> Output:`{"name": "John", "age": 30 }`             |                                                                                                                                                                  |
| `from_entries`       | Converts an array of objects with `key` and `value` properties into a single object                                                 | Input: `[{"key": "name", "value": "John"}, {"key": "age", "value": 30}, {"key": "city", "value": null}]` <br /> Expression: `from_entries(@)` <br /> Output: `{"name": "John", "age": 30, "city": null}` |                                                                                                                                                                  |
| `hash`               | Calculates a hash using the `hash_name` hash function and returns its hexadecimal representation                                    | Input: `{"some_str": "some_value"}` <br /> Expression: `hash(some_str, &#96;sha1&#96;)` <br /> Output: `8c8181715...`                                                                                    | Supported algorithms: sha1 (default), sha256, md5, sha384, sha3_384, blake2b, sha512, sha3_224, sha224, sha3_256, sha3_512, blake2s                              |
| `in`                 | Checks if an element matches any value in a list of values                                                                          | Input: `{"el": "b"}` <br /> Expression: `in(el, `["a", "b", "c"]`)` <br /> Output: `True`                                                                                                                |                                                                                                                                                                  |
| `left`               | Returns a specified number of characters from the start of a given text string                                                      | Input: `{"greeting": "hello world!"}` <br /> Expression: `left(greeting, `5`)` <br /> Output: `hello`                                                                                                    |                                                                                                                                                                  |
| `lower`              | Converts all uppercase characters in a string into lowercase characters                                                             | Input: `{"fname": "John"}` <br /> Expression: `lower(fname)` <br /> Output: `john`                                                                                                                       |                                                                                                                                                                  |
| `mid`                | Returns a specified number of characters from the middle of a given text string                                                     | Input: `{"greeting": "hello world!"}` <br /> Expression: `mid(greeting, `4`, `3`)` <br /> Output: `o w`                                                                                                  |                                                                                                                                                                  |
| `json_parse`         | Returns parsed object from the given JSON string                                                                                    | Input: `{"data": '{"greeting": "hello world!"}'}` <br /> Expression: `json_parse(data)` <br /> Output: `{"greeting": "hello world!"}`                                                                    |                                                                                                                                                                  |
| `regex_replace`      | Replaces a string that matches a regular expression                                                                                 | Input: `{"text": "Banana Bannnana"}` <br /> Expression: `regex_replace(text, 'Ban\w+', 'Apple Apple')` <br /> Output: `Apple Apple`                                                                      |                                                                                                                                                                  |
| `replace`            | Replaces all the occurrences of a substring with a new one                                                                          | Input: `{"sentence": "one four three four!"}` <br /> Expression: `replace(sentence, 'four', 'two')` <br /> Output: `one two three two!`                                                                  |                                                                                                                                                                  |
| `right`              | Returns a specified number of characters from the end of a given text string                                                        | Input: `{"greeting": "hello world!"}` <br /> Expression: `right(greeting, `6`)` <br /> Output: `world!`                                                                                                  |                                                                                                                                                                  |
| `split`              | Splits a string into a list of strings after breaking the given string by the specified delimiter (comma by default)                | Input: `{"departments": "finance,hr,r&d"}` <br /> Expression: `split(departments)` <br /> Output: `['finance', 'hr', 'r&d']`                                                                             | Default delimiter is comma - a different delimiter can be passed to the function as the second argument, for example: `split(departments, ';')`                  |
| `time_delta_days`    | Returns the number of days between a given `dt` and now (positive) or the number of days that have passed from now (negative)       | Input: `{"dt": '2021-10-06T18:56:16.701670+00:00'}` <br /> Expression: `time_delta_days(dt)` <br /> Output: `365`                                                                                        | If `dt` is a string, ISO datetime (2011-11-04T00:05:23+04:00, for example) is assumed. If `dt` is a number, Unix timestamp (1320365123, for example) is assumed. |
| `time_delta_seconds` | Returns the number of seconds between a given `dt` and now (positive) or the number of seconds that have passed from now (negative) | Input: `{"dt": '2021-10-06T18:56:16.701670+00:00'}` <br /> Expression: `time_delta_days(dt)` <br /> Output: `31557600`                                                                                   | If `dt` is a string, ISO datetime (2011-11-04T00:05:23+04:00, for example) is assumed. If `dt` is a number, Unix timestamp (1320365123, for example) is assumed. |
| `to_entries`         | Converts a given object into an array of objects with `key` and `value` properties                                                  | Input: `{"name": "John", "age": 30, "city": null}` <br /> Expression: `to_entries(@)` <br /> Output: `[{"key": "name", "value": "John"}, {"key": "age", "value": 30}, {"key": "city", "value": null}]`   |                                                                                                                                                                  |
| `upper`              | Converts all lowercase characters in a string into uppercase characters                                                             | Input: `{"fname": "john"}` <br /> Expression: `upper(fname)` <br /> Output: `JOHN`                                                                                                                       |                                                                                                                                                                  |
| `uuid`               | Generates a random UUID4 and returns it as a string in standard format                                                              | Input: None <br /> Expression: `uuid()` <br /> Output: `3264b35c-ff5d-44a8-8bc7-9be409dac2b7`                                                                                                            |                                                                                                                                                                  |
| `xml_to_dict`        | Converts an XML string to a dictionary                                                                                              | Input: `{"xml": "<root><name>John</name><age>30</age></root>"}` <br /> Expression: `xml_to_dict(xml)` <br /> Output: `{"root": {"name": "John", "age": "30"}}`                                           | Returns `null` if the input is `null`; returns an empty string if the input is an empty string                                                                   |

