> For the complete documentation index, see [llms.txt](https://guide.indigo.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide.indigo.ai/getting-started/workspace/variables/functions.md).

# Functions

[Variables](/getting-started/workspace/variables.md) let you store and reuse values across a conversation. **Functions** let you *transform* those values inline — round a number, format a date, clean up text, parse JSON, or reshape a list — right where you use them, without extra logic blocks.

You can apply functions in any field that supports variable interpolation: [Text](/getting-started/agents-workflows-and-triggers/blocks/message-blocks/text-block.md), [Set Values](/getting-started/agents-workflows-and-triggers/blocks/logic-blocks/set-values-block.md), [Condition](/getting-started/agents-workflows-and-triggers/blocks/logic-blocks/condition-block.md), [API](/getting-started/agents-workflows-and-triggers/blocks/action-blocks/api-block.md), and [Prompt](/getting-started/agents-workflows-and-triggers/blocks/utility-blocks/prompt-block.md) blocks, among others.

{% hint style="info" %}
New to variable interpolation and the `{{ ... }}` syntax? Start with the [Variables](/getting-started/workspace/variables.md) guide, then come back here to transform those values.
{% endhint %}

## How Functions Work

A function is an operation — a calculation, an edit, or a check — applied to a value. You apply one with the pipe character (`|`):

```
{{ variable | function }}
```

You can chain as many functions as you like. They run **left to right**, each receiving the output of the previous one:

```
{{ variable | function1 | function2 | function3 }}
```

Whitespace inside the braces is ignored, and any invalid function (or a reference to a variable that doesn't exist) is simply skipped.

Each function can take zero, one, or more **arguments**. A single argument follows a colon:

```
// name = "Dante"
{{ name | append: "-san" }}   // Dante-san
```

Multiple arguments are separated by commas:

```
// name = "Dante"
{{ name | regex_replace: "D", "f" }}   // fante
```

{% hint style="info" %}
**Good to know**

* **The result is always text.** Whatever the input type — number, date, list — the value produced by a function is returned as a string.
* **Setting and transforming in the same step.** All variables inside a single [Set Values](/getting-started/agents-workflows-and-triggers/blocks/logic-blocks/set-values-block.md) block are evaluated at the same time. If you need to set a variable *and then* apply a function to that new value within the same flow, use **two separate Set Values blocks** — otherwise the function reads the old value.
* **A malformed function can break an Answer.** If a function is written incorrectly, the Answer that contains it may fail to trigger when you test it in the chat preview. Check your syntax if a tested Answer doesn't fire.
  {% endhint %}

## 🧰 General

### default

Sets a fallback value for any variable that has no value assigned. `default` returns the fallback when the input is `nil`, `false`, or empty.

```
// product_price not in context and has no default value
{{ product_price | default: 2.99 }}   // 2.99
```

## 🔢 Number Operations

### abs

Returns the absolute value of a number. Also works on a string that contains a number.

```
{{ -17 | abs }}        // 17
{{ 4 | abs }}          // 4
{{ "-19.86" | abs }}   // 19.86
```

### at\_least

Limits a number to a minimum value.

```
{{ 4 | at_least: 5 }}   // 5
{{ 4 | at_least: 3 }}   // 4
```

### at\_most

Limits a number to a maximum value.

```
{{ 4 | at_most: 5 }}   // 4
{{ 4 | at_most: 3 }}   // 3
```

### ceil

Rounds a number **up** to the nearest integer. The input is converted to a number first.

```
{{ 1.2 | ceil }}       // 2
{{ 2.0 | ceil }}       // 2
{{ 183.357 | ceil }}   // 184
{{ "3.5" | ceil }}     // 4
```

### divided\_by

Divides a number by another number. The result type matches the divisor: divide by an integer and you get an integer (rounded down); divide by a float and you get a float.

```
{{ 16 | divided_by: 4 }}     // 4
{{ 5 | divided_by: 3 }}      // 1
{{ 20 | divided_by: 7 }}     // 2
{{ 20 | divided_by: 7.0 }}   // 2.857142857142857
{{ 10 | divided_by: 2.0 }}   // 5.0
```

### floor

Rounds a number **down** to the nearest integer. The input is converted to a number first.

```
{{ 1.2 | floor }}       // 1
{{ 2.0 | floor }}       // 2
{{ 183.357 | floor }}   // 183
{{ "3.5" | floor }}     // 3
```

### minus

Subtracts one number from another.

```
{{ 4 | minus: 2 }}         // 2
{{ 16 | minus: 4 }}        // 12
{{ 183.357 | minus: 12 }}  // 171.357
```

### modulo

Returns the remainder of a division.

```
{{ 3 | modulo: 2 }}         // 1
{{ 24 | modulo: 7 }}        // 3
{{ 183.357 | modulo: 12 }}  // 3.357
```

### plus

Adds one number to another.

```
{{ 4 | plus: 2 }}         // 6
{{ 16 | plus: 4 }}        // 20
{{ 183.357 | plus: 12 }}  // 195.357
```

### round

Rounds a number to the nearest integer, or to the number of decimal places passed as an argument.

```
{{ 1.2 | round }}         // 1
{{ 2.7 | round }}         // 3
{{ 183.357 | round: 2 }}  // 183.36
```

### times

Multiplies one number by another.

```
{{ 3 | times: 2 }}         // 6
{{ 24 | times: 7 }}        // 168
{{ 183.357 | times: 12 }}  // 2200.284
```

### random

Returns a random element. Applied to a string, it returns a random character; with a numeric argument, it returns a random integer in that range.

```
{{ "abc" | random }}   // a random character of the string
{{ 1 | random: 7 }}    // a random number between 1 and 7
```

## 🔤 Text Operations

### append

Adds a string to the end of another string. Also accepts a variable as its argument.

```
{{ "/my/fancy/url" | append: ".html" }}   // /my/fancy/url.html

// filename = "/index.html"
{{ "website.com" | append: filename }}    // website.com/index.html
```

### capitalize

Capitalizes the first character of a string and lowercases the rest. Only the first character is affected.

```
{{ "title" | capitalize }}          // Title
{{ "my GREAT title" | capitalize }} // My great title
```

### downcase

Lowercases every character of a string.

```
{{ "Parker Moore" | downcase }}   // parker moore
{{ "apple" | downcase }}          // apple
```

### upcase

Uppercases every character of a string.

```
{{ "Parker Moore" | upcase }}   // PARKER MOORE
{{ "APPLE" | upcase }}          // APPLE
```

### lstrip

Removes all whitespace (tabs, spaces, newlines) from the **left** side of a string. Whitespace between words is preserved.

```
{{ "          So much room for activities          " | lstrip }}!
// So much room for activities          !
```

### rstrip

Removes all whitespace from the **right** side of a string.

```
{{ "          So much room for activities          " | rstrip }}!
// So much room for activities!
```

### strip

Removes all whitespace from **both** sides of a string.

```
{{ "          So much room for activities          " | strip }}!
// So much room for activities!
```

### strip\_newlines

Removes newline characters (line breaks) from a string.

### prepend

Adds a string to the beginning of another string. Also accepts a variable as its argument.

```
{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}
// Some fruit: apples, oranges, and bananas
```

### remove

Removes every occurrence of a substring from a string.

```
{{ "I strained to see the train through the rain" | remove: "rain" }}
// I sted to see the t through the
```

### remove\_first

Removes only the **first** occurrence of a substring.

```
{{ "I strained to see the train through the rain" | remove_first: "rain" }}
// I sted to see the train through the rain
```

### replace

Replaces every occurrence of the first argument with the second.

```
{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}
// Take your protein pills and put your helmet on
```

### replace\_first

Replaces only the **first** occurrence of the first argument with the second.

```
{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}
// Take your protein pills and put my helmet on
```

### slice

Returns a substring (or a slice of an array) starting at the given index. An optional second argument sets the length. Indices start at 0; a negative index counts from the end.

```
{{ "Indigo" | slice: 0 }}      // I
{{ "Indigo" | slice: 2 }}      // d
{{ "Indigo" | slice: 2, 5 }}   // digo
{{ "Indigo" | slice: -3, 2 }}  // ig
{{ "202050401" | slice: 0, 4 }} // 2020
{{ "John, Paul, George, Ringo" | split: ", " | slice: 1, 2 }} // PaulGeorge
```

{% hint style="warning" %}
`slice` expects a **string**, not an integer. If you pass a numeric value, wrap it in quotes (or make sure it is already a string) to avoid errors.
{% endhint %}

### strip\_html

Removes HTML tags from a string.

```
{{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }}
// Have you read Ulysses?
```

A common use is cleaning a context variable before injecting it into a [Prompt block](/getting-started/agents-workflows-and-triggers/blocks/utility-blocks/prompt-block.md):

```
{{ $context_2 | strip_html }}
```

### truncate

Shortens a string to the given number of characters. If the string is longer, an ellipsis (`...`) is appended and counted in the total.

```
{{ "Ground control to Major Tom." | truncate: 20 }}
// Ground control to...
```

An optional second argument sets a custom trailing sequence. Its length counts toward the character limit — so to truncate to exactly 10 characters with a 3-character ellipsis, pass `13`.

```
{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }}
// Ground control, and so on
{{ "Ground control to Major Tom." | truncate: 20, "" }}
// Ground control to Ma
```

### truncatewords

Shortens a string to the given number of **words**, appending an ellipsis when the string is longer.

```
{{ "Ground control to Major Tom." | truncatewords: 3 }}        // Ground control to...
{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}  // Ground control to--
{{ "Ground control to Major Tom." | truncatewords: 3, "" }}    // Ground control to
```

### translate

Translates a text variable into a target language, identified by its language code.

```
{{ var | translate: "EN-US" }}
```

## 🔎 Regular Expressions

Regular expressions (regex) let you match and extract patterns inside text. Two functions use them: `regex` (extract) and `regex_replace` (substitute).

### regex

Extracts every match of a regex pattern from a string. The result is a list: for each match, the first element is the full match and any following elements are the groups captured with parentheses.

```
{{ "This is a number: 2345678!" | regex: "\d+" }}   // 2345678
{{ "My phone number is 234-5678" | regex: "\d+" }}  // [["234"], ["5678"]]
```

You can make the match case-insensitive with a second argument:

```
{{ "Alaar" | regex: "A", "i" }}   // [["A"], ["a"], ["a"]]
```

A regex is a rule describing a pattern in text — for example, `dd` matches a double `d`. A rule combines **identifiers** (which characters to match) with **quantifiers** (how many).

Common identifiers:

| Identifier       | Description                                                                                                                           | Example match                                  |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- |
| `a`              | A single character. Any key can be matched this way except some reserved characters. Uppercase and lowercase are different.           | Ci**a**o                                       |
| `mela`           | A sequence of characters.                                                                                                             | I'd like to eat an **apple**                   |
| `\*`             | The literal `*`. Reserved characters (`* [ ] { } .` and `\` itself) are matched by prefixing a backslash.                             | All done\*\*\*\*\*                             |
| `[abc]`          | A class: any one of the characters inside the brackets.                                                                               | How the trees grow here — **c**, **a**, **b**… |
| `[0-9]`          | A range inside a class. `[0-9]` is any digit; `[A-Z]`, `[a-z]`, `[A-Za-z]` work the same way.                                         | The area code is **081**                       |
| `([a-z][0-9])`   | A group: collects identifiers so a quantifier applies to all of them. Groups are returned as captures in the result.                  |                                                |
| `(?:[a-z][0-9])` | A non-capturing group: starting with `?:` excludes the group from the result. Useful to structure a rule without returning that part. |                                                |

Common quantifiers:

| Quantifier | Description                                                                  |
| ---------- | ---------------------------------------------------------------------------- |
| `*`        | Any number of the identifier (including zero)                                |
| `?`        | At most one                                                                  |
| `+`        | At least one (one or more)                                                   |
| `{0,3}`    | A specific range — here, 0 to 3. You can give only the lower or upper bound. |

{% hint style="info" %}
This is a brief introduction to regular expressions, not a complete reference. For a deeper dive, see one of the many resources online, such as the [Wikipedia article on regular expressions](https://en.wikipedia.org/wiki/Regular_expression).
{% endhint %}

### regex\_replace

Replaces the parts of a string that match a regex. Chains well to apply several substitutions in sequence.

```
{{ "This is a number: 2345678!" | regex_replace: "\d+", "" | regex_replace: " is ", " is not " }}
// This is not a number: !
```

## 🔐 Text Encoding

### base64\_decode

Decodes a Base64 string.

```
{{ "YXBwbGVz" | base64_decode }}   // apples
```

### base64\_encode

Encodes a string as Base64.

```
{{ "apples" | base64_encode }}   // YXBwbGVz
```

### escape

Escapes a string by replacing characters with their escape sequences — for example so the string can be used in a URL. Strings with nothing to escape are unchanged.

```
{{ "Have you read 'James & the Giant Peach'?" | escape }}
// Have you read &#39;James &amp; the Giant Peach&#39;?
{{ "Tetsuro Takara" | escape }}   // Tetsuro Takara
```

### escape\_once

Escapes a string without re-escaping entities that are already escaped.

```
{{ "1 < 2 & 3" | escape_once }}          // 1 &lt; 2 &amp; 3
{{ "1 &lt; 2 &amp; 3" | escape_once }}   // 1 &lt; 2 &amp; 3
```

### newline\_to\_br

Inserts an HTML line break (`<br />`) before every newline (`\n`) in a string.

### url\_decode

Decodes a URL-encoded string (for example, one produced by `url_encode`).

```
{{ "%27Stop%21%27+said+Fred" | url_decode }}   // 'Stop!' said Fred
```

### url\_encode

Converts URL-unsafe characters into percent-encoded characters. Note that a space becomes `+` rather than a percent-encoded character.

```
{{ "john@indigo.ai" | url_encode }}   // john%40indigo.ai
{{ "Tetsuro Takara" | url_encode }}    // Tetsuro+Takara
```

## 🔀 Splitting & Converting

### split

Splits a string into an array using the argument as the separator. Commonly used to turn comma-separated values into an array.

```
{{ "John, Paul, George, Ringo" | split: ", " | join: " and " }}
// John and Paul and George and Ringo
```

### join

Combines the elements of an array into a single string, using the argument as the separator.

```
{{ "Mario, Luigi" | split: ", " | join: " and " }}   // Mario and Luigi
```

### format\_list

Displays a list in its correct format. By default, printing a list variable concatenates its values with no separators; `format_list` renders it as a proper list — useful for display or for passing to third-party services.

```
// list = [1, 2, 3, "four"]
{{ list }}                  // 123four
{{ list | format_list }}    // [1,2,3,"four"]
```

{% hint style="info" %}
This is the recommended workaround for the List-printing limitation described in the [Variables](/getting-started/workspace/variables.md) guide.
{% endhint %}

### to\_integer

Converts a value to an integer. A float is rounded; for an array, every element is converted.

```
{{ "12" | to_integer }}   // 12
{{ 6.7 | to_integer }}    // 7
{{ "1.2, 6.54, 9" | split: ", " | to_integer | join: " " }}  // 1 7 9
{{ "1.2, 6.54, 9" | split: ", " | to_integer | sum }}        // 17
```

### to\_float

Converts a value to a float. For an array, every element is converted.

```
{{ "12" | to_float }}   // 12.0
{{ 6.7 | to_float }}    // 6.7
{{ "1.2, 6.54, 9" | split: ", " | to_float | join: " " }}  // 1.2 6.54 9.0
{{ "1.2, 6.54, 9" | split: ", " | to_float | sum }}        // 16.74
```

## 📅 Working with Dates

### date

Converts a timestamp to another date format. The format syntax matches [`strftime`](http://strftime.net/).

```
{{ published_at | date: "%a, %b %d, %y" }}   // Fri, Jul 17, 15
{{ published_at | date: "%Y" }}              // 2015
```

To get the current time, pass the special word `"now"` (or `"today"`):

```
This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}.
// This page was last updated at 2023-07-07 14:07.
```

### parse\_date

Converts a date string in `YYYY-MM-DD` format into a datetime structure, which makes further date and time operations easier. Accepts an optional **timezone**.

```
{{ "2024-07-18" | parse_date }}
// 2024-07-18 00:00:00Z

{{ "2024-07-18" | parse_date: "Europe/Rome" }}
// 2024-07-18 00:00:00+02:00 CEST Europe/Rome
```

### parse\_date\_and\_time

Like `parse_date`, but also takes a time string in `HH:mm:ss` format. An optional third argument sets the timezone.

```
{{ "2024-07-18" | parse_date_and_time: "10:06:28" }}
// 2024-07-18 10:06:28Z

{{ "2024-07-18" | parse_date_and_time: "10:06:28", "Europe/Rome" }}
// 2024-07-18 10:06:28+02:00 CEST Europe/Rome
```

### timestamp\_to\_datetime

Turns an integer representing seconds since 1970-01-01 (a Unix timestamp) into a datetime structure. Accepts an optional timezone.

```
{{ $timestamp | timestamp_to_datetime }}
// 2024-07-18 10:06:28Z
```

### shift\_datetime\_timezone

Shifts a datetime to a different timezone, adjusting the date and time accordingly.

```
{{ $timestamp | timestamp_to_datetime | shift_datetime_timezone: "Europe/Rome" }}
// 2024-07-18 12:06:28+02:00 CEST Europe/Rome
```

### add\_time

Adds time to a datetime. The first argument is the amount (a positive or negative integer); the second is the unit:

* `d` — days
* `h` — hours
* `m` — minutes
* `s` — seconds (the default if omitted)

```
{{ $timestamp | timestamp_to_datetime | add_time: -5 }}
// 5 seconds earlier

{{ $timestamp | timestamp_to_datetime | add_time: 5, "d" }}
// 5 days later
```

### format\_datetime

Turns a datetime into a string following the given format. Each element is written as `%<padding><length><element>`:

* **padding** (optional): `-` none, `_` pad with spaces, `0` pad with zeros
* **length** (optional): an integer for how much space the element should occupy
* **element**: a character selecting which piece of the datetime to output

| Element | Description                           | Example        |
| ------- | ------------------------------------- | -------------- |
| `a`     | Abbreviated day name                  | Mon            |
| `A`     | Full day name                         | Monday         |
| `b`     | Abbreviated month name                | Jan            |
| `B`     | Full month name                       | January        |
| `d`     | Day of the month                      | 01, 31         |
| `f`     | Microseconds (no padding/length)      | 000000, 999999 |
| `H`     | Hour (24-hour clock)                  | 00, 23         |
| `I`     | Hour (12-hour clock)                  | 01, 12         |
| `j`     | Day of the year                       | 001, 366       |
| `m`     | Month                                 | 01, 12         |
| `M`     | Minute                                | 00, 59         |
| `p`     | "AM" or "PM"                          | AM, PM         |
| `P`     | "am" or "pm"                          | am, pm         |
| `q`     | Quarter                               | 1, 2, 3, 4     |
| `s`     | Seconds since 1970-01-01 00:00:00 UTC | 1565888877     |
| `S`     | Seconds                               | 00, 59         |
| `u`     | Day of the week, starting Monday      | 1, 7           |
| `y`     | Two-digit year                        | 01, 86, 18     |
| `Y`     | Year                                  | 0001, 1986     |
| `z`     | UTC offset (+hhmm / -hhmm)            | +0300, -0530   |
| `Z`     | Timezone abbreviation                 | CET, BRST      |
| `%`     | A literal "%"                         | %              |

```
{{ "2024-07-18" | parse_date_and_time: "10:06:28" | format_datetime: "%u" }}
// 4
{{ "2024-07-18" | parse_date_and_time: "10:06:28" | format_datetime: "%A %d %B" }}
// Thursday 18 July
```

An optional language argument changes the day and month names. Supported languages are `en` (default) and `it`.

```
{{ "2024-07-18" | parse_date_and_time: "10:06:28" | format_datetime: "%A %d %B", "it" }}
// Giovedì 18 Luglio
```

### compare\_with\_date

Compares a datetime with a date in `YYYY-MM-DD` format. Returns `gt` (datetime is later), `eq` (same date), or `lt` (datetime is earlier).

```
{{ '2024-10-17' | parse_date_and_time: '12:00:00', 'Europe/Rome' | compare_with_date: "2024-10-16" }}  // gt
{{ '2024-10-17' | parse_date_and_time: '12:00:00', 'Europe/Rome' | compare_with_date: "2024-10-17" }}  // eq
{{ '2024-10-17' | parse_date_and_time: '12:00:00', 'Europe/Rome' | compare_with_date: "2024-10-18" }}  // lt
```

### compare\_with\_time

Compares a datetime with a time in `HH:mm:ss` format. Returns `gt`, `eq`, or `lt`.

```
{{ '2024-10-17' | parse_date_and_time: '12:00:00', 'Europe/Rome' | compare_with_time: "00:00:00" }}  // gt
{{ '2024-10-17' | parse_date_and_time: '12:00:00', 'Europe/Rome' | compare_with_time: "12:00:00" }}  // eq
{{ '2024-10-17' | parse_date_and_time: '12:00:00', 'Europe/Rome' | compare_with_time: "13:00:00" }}  // lt
```

## 🗂️ Working with JSON

### get

Retrieves a nested value from an object, or a value at a specific position in an array (starting at 0).

```
// obj = {"title": "Hello"}
{{ obj | get: "title" }}              // Hello
{{ "A,b,c" | split: "," | get: 1 }}   // b
```

### json\_decode

Parses a JSON string into a map (a structure you can traverse, like a parsed JSON object).

```
{{ "{\"a\":\"b\"}" | json_decode | get: "a" }}   // b
```

### json\_encode

Encodes a value into a JSON string.

```
// obj = {"a": "b"}
{{ obj | json_encode }}   // {"a":"b"}
```

### json\_to\_markdown

Converts a list of maps into a Markdown table. The keys of the first map are used as the columns. An optional argument is a comma-separated list of labels, to filter or reorder columns.

{% code overflow="wrap" %}

```
{{ '[{"Name":"Alice","Year":2019,"Role":"Engineer"},{"Name":"Bob","Year":2020,"Role":"Designer"}]' | json_decode | json_to_markdown: "Year,Name" }}
// Year|Name
// 2019|Alice
// 2020|Bob
```

{% endcode %}

### json\_path

JSONPath is a standard for retrieving and filtering data from a JSON document using a path expressed as a string. The platform supports a subset of [JSONPath](https://goessner.net/articles/JsonPath/). Always run `json_decode` first, since `json_path` works on maps and lists.

For the examples below, assume the variable `var` holds this JSON:

```json
{
  "company": "Acme",
  "people": [
    { "name": "Alice", "year": 2019 },
    { "name": "Bob",   "year": 2020 },
    { "name": "Carol", "year": 2019 }
  ]
}
```

**Read a top-level field.** Every path starts with `$` (the root). The `.` operator accesses a key; chain operators to reach nested keys.

```
{{ var | json_decode | json_path: "$.company" }}   // Acme
```

**Read an item by index.** Use array syntax; numbering starts at 0.

```
{{ var | json_decode | json_path: "$.people[1]" }}   // {"name": "Bob", "year": 2020}
```

**Filter a list.** Inside the brackets, `?` introduces a condition and `@` refers to the current element being tested.

{% code overflow="wrap" %}

```
{{ var | json_decode | json_path: "$.people[?(@.year == 2019)]" | json_encode }}
// [{"name": "Alice", "year": 2019}, {"name": "Carol", "year": 2019}]
```

{% endcode %}

**Extract a field from every item.** The `:` operator defines a range `X:Y`, where `X` is the start index (from 0) and `Y` is the first index to exclude. Omit both to mean the whole list.

```
{{ var | json_decode | json_path: "$.people[:].name" | json_encode }}
// ["Alice", "Bob", "Carol"]
{{ var | json_decode | json_path: "$.people[1:3].name" | json_encode }}
// ["Bob", "Carol"]
```

**Match with OR.** Combine conditions to extract items matching any of them.

{% code overflow="wrap" %}

```
{{ var | json_decode | json_path: '$[?(@.name == "Alice"), ?(@.name == "Carol")]' | json_encode }}
```

{% endcode %}

## 📄 Working with CSV

### csv\_to\_json

Turns a CSV into a list of maps keyed by the CSV headers. The result is a map with an `ok` key (the rows parsed correctly) and an `errors` key (the list of errors). An optional argument sets the column separator (default: comma).

{% code overflow="wrap" %}

```
{{ "Name,Year,Role\nAlice,2019,Engineer\nBob,2020,Designer" | csv_to_json: "," }}
// {errors: [], ok: [{"Name":"Alice","Year":2019,"Role":"Engineer"},{"Name":"Bob","Year":2020,"Role":"Designer"}]}
```

{% endcode %}

### csv\_to\_markdown

Turns a CSV into a Markdown table. Optional arguments: the column separator (default: comma) and a comma-separated list of labels to filter or reorder columns.

{% code overflow="wrap" %}

```
{{ "Name,Year,Role\nAlice,2019,Engineer\nBob,2020,Designer" | csv_to_markdown: ",", "Year,Name" }}
// Year|Name
// 2019|Alice
// 2020|Bob
```

{% endcode %}

## 📋 Working with Lists

Lists are a special case of JSON, so the JSON functions above also apply to them.

### compact

Removes all `nil` values from an array.

```
// list = [0, 1, 4, nil, 9, 2, nil, 0]
{{ list | join: "+" }}             // 0+1+4++9+2++0
{{ list | compact | join: "+" }}   // 0+1+4+9+2+0
```

### contains

Checks whether a list contains an element. Returns `true` or `false`.

```
// list = [1, 0, -9]
{{ list | contains: 0 }}     // true
{{ list | contains: "a" }}   // false
```

### first

Returns the first element of an array.

```
{{ "Ground control to Major Tom." | split: " " | first }}   // Ground
```

### last

Returns the last element of an array.

```
{{ "Ground control to Major Tom." | split: " " | last }}   // Tom.
```

### size

Counts the number of elements in a list, or the number of characters in a string.

```
{{ "Ground control to Major Tom." | size }}        // 28
{{ "one, two, three" | split: ", " | size }}       // 3
```

### push

Adds an element to the end of a list.

```
{{ "0, 1, 2" | split: ", " | push: "3" }}   // 0123
```

### pop

Removes the last element of a list.

```
{{ "0, 1, 2" | split: ", " | pop }}   // 01
```

### unshift

Adds an element to the beginning of a list.

```
{{ "0, 1, 2" | split: ", " | unshift: "-1" }}   // -1012
```

### shift

Removes the first element of a list.

```
{{ "0, 1, 2" | split: ", " | shift }}   // 12
```

### reverse

Reverses the order of the elements in a list. To reverse a string, split it first, then rejoin.

```
{{ "apples, oranges, peaches, plums" | split: ", " | reverse | join: ", " }}
// plums, peaches, oranges, apples
{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}
// .moT rojaM ot lortnoc dnuorG
```

### sort

Sorts the elements of an array in case-sensitive alphabetical order.

```
{{ "zebra, octopus, giraffe, Sally Snake" | split: ", " | sort | join: ", " }}
// Sally Snake, giraffe, octopus, zebra
```

### sort\_natural

Sorts the elements of an array in case-insensitive alphabetical order.

```
{{ "zebra, octopus, giraffe, Sally Snake" | split: ", " | sort_natural | join: ", " }}
// giraffe, octopus, Sally Snake, zebra
```

### sum

Adds up all the elements of an array.

```
{{ "1, 4, 0, 12" | split: ", " | to_integer | sum }}   // 17
```

### uniq

Removes duplicate elements from a list.

```
{{ "ants, bugs, bees, bugs, ants" | split: ", " | uniq | join: ", " }}
// ants, bugs, bees
```

### merge

Merges two lists into one containing the elements of both. The lists can be either list values or JSON in text form.

```
// list_1 = [1, 2, 3]
// list_2 = [4, 5, 2]
{{ list_1 | merge: list_2 }}   // [1, 2, 3, 4, 5, 2]
```

{% hint style="info" %}
Looking for `concat`? It is deprecated — use `merge` instead, which accepts a list as its argument.
{% endhint %}

### unique\_by

Removes duplicates from a list of maps, comparing on the given key. When duplicates are found, the first one encountered is kept.

{% code overflow="wrap" %}

```
// list = [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}, {"id": 3, "name": "Alice"}]
{{ list | unique_by: "name" }}
// [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]
```

{% endcode %}

An optional second argument removes entries whose value is `null`:

{% code overflow="wrap" %}

```
// list = [{"id": 1, "name": null}, {"id": 2, "name": "Bob"}, {"id": 3, "name": null}]
{{ list | unique_by: "name" }}        // [{"id": 1, "name": null}, {"id": 2, "name": "Bob"}]
{{ list | unique_by: "name", true }}  // [{"id": 2, "name": "Bob"}]
```

{% endcode %}

### where

Extracts from a list of maps only the elements whose given key has the given value.

{% code overflow="wrap" %}

```
// list = [{"id": 1, "first_name": "Alice", "last_name": "Stone"}, {"id": 2, "first_name": "Bob", "last_name": "Lee"}, {"id": 3, "first_name": "Alice", "last_name": "Reed"}]
{{ list | where: "first_name", "Alice" }}
// [{"id": 1, "first_name": "Alice", "last_name": "Stone"}, {"id": 3, "first_name": "Alice", "last_name": "Reed"}]
```

{% endcode %}

Values are compared as strings by default, which can cause false negatives for numbers. Pass a third argument with the data type — `text` (default), `integer`, or `float` — to compare correctly.

{% code overflow="wrap" %}

```
// list = [{"id": 1, "type": "number"}, {"id": "1", "type": "text"}]
{{ list | where: "id", 1 }}              // [{"id": "1", "type": "text"}]
{{ list | where: "id", 1, "integer" }}   // [{"id": 1, "type": "number"}]
```

{% endcode %}

## 🖼️ Working with Images

### merge\_images

Overlays one image on top of another. Images can be URLs or Base64-encoded data — both valid in HTML. The optional `x` and `y` arguments set the anchor point where the second image is placed on the first:

* **Integers** align to the pixel. A negative value counts from the end of the image (from the right for `x`, from the bottom for `y`).
* **Keywords** set standard alignments: `left`, `center`, `right` for `x`; `top`, `middle`, `bottom` for `y`.

```
{{ image_1 | merge_images: image_2, x, y }}
// data:image/png;base64,...
```

## Next Steps

* Revisit [Variables](/getting-started/workspace/variables.md) to see how values get into your flows in the first place.
* Browse [System Variables](/getting-started/workspace/variables/system-variables.md) — many (like `$date`, `$timestamp`, `$context`) pair naturally with the functions on this page.
* Put functions to work in the [Set Values](/getting-started/agents-workflows-and-triggers/blocks/logic-blocks/set-values-block.md) and [Condition](/getting-started/agents-workflows-and-triggers/blocks/logic-blocks/condition-block.md) blocks.
