Default Filters
Filters transform data before it's rendered. They're applied using the pipe (|) character after a variable. APITemplate.io supports all standard Jinja2 filters out of the box.
Syntax
{{ variable | filter_name }}
You can chain multiple filters:
{{ name | lower | capitalize }}
You can also pass arguments to filters:
{{ items | join(", ") }}
{{ [x, y, z] | join | upper }}
Text filters
capitalize
Capitalizes the first character of a string:
{{ "mango is fruit" | capitalize }}
Output: Mango is fruit
lower
Converts to lowercase:
{{ "Mango is a fruit" | lower }}
Output: mango is a fruit
upper
Converts to uppercase:
{{ "Mango is a fruit" | upper }}
Output: MANGO IS A FRUIT
title
Capitalizes the first letter of each word:
{{ "mango is fruit" | title }}
Output: Mango Is Fruit
replace
Replaces occurrences of a substring:
{{ "Hello World" | replace("World", "Jinja2") }}
Output: Hello Jinja2
default
Provides a fallback value when a variable is undefined or empty:
{{ company_name | default("Not specified") }}
{{ phone | default("N/A") }}
Number filters
max / min
Get the largest or smallest item from a list:
{{ [1, 2, 3] | max }}
Output: 3
round
Round a number:
{{ 3.14159 | round(2) }}
Output: 3.14
abs
Absolute value:
{{ -5 | abs }}
Output: 5
List filters
join
Join a list into a string:
{{ ["red", "green", "blue"] | join(", ") }}
Output: red, green, blue
length
Get the number of items:
{{ items | length }} items total
sum
Sum a list of numbers:
Total: {{ [10, 20, 30] | sum }}
Output: Total: 60
first / last
Get the first or last item:
{{ ["a", "b", "c"] | first }}
Output: a
map
Apply a filter or attribute lookup to a list:
{{ users | map(attribute='name') | join(", ") }}
random
Return a random item from a list:
{{ ["red", "green", "blue"] | random }}
Other built-in filters
Jinja2 includes many more filters. Here are some commonly used ones:
| Filter | Description | Usage |
|---|---|---|
urlencode | URL-encode a string | url | urlencode |
format | Apply printf-style formatting | "%s - %s" | format("Hello", "World") |
int / float | Convert to int or float | "42" | int |
trim | Strip leading/trailing whitespace | name | trim |
truncate | Truncate a string | text | truncate(50) |
wordcount | Count words in a string | text | wordcount |
sort | Sort a list | items | sort |
unique | Remove duplicates from a list | items | unique |
reverse | Reverse a list or string | items | reverse |
batch | Group items into batches | items | batch(3) |
selectattr | Filter objects by attribute | users | selectattr("active") |
For the complete list of Jinja2 built-in filters, see the official Jinja2 documentation.
Next steps
- APITemplate.io Filters — QR codes, barcodes, tables, dates, and currency
- Examples — practical template patterns