Expression Transformation and Judgment (Filters)
In workflow expressions, the function to perform "transformation" and "judgment" on values is provided as filters.
In general programming terms, it's similar to a function that takes input (value) and returns output (transformed value).
How to Read Filters (Pipe Notation)
The | (pipe) is used to apply filters from left to right.
{{ 'ABC' | to_lower | trim }}
This example means "convert 'ABC' to lowercase and remove leading and trailing whitespace."
Using filters, you can simply write a wide range of data transformations, such as string processing, date and time manipulation, path processing, and hashing.
Basic Filters
| Filter Name | Description | Example |
|---|---|---|
size | Returns the number of elements | {{ [1,2,3] | size}} → 3 |
type | Returns the type name | {{ 123 | type}} → Int32 |
String Manipulation
| Filter Name | Description | Example |
|---|---|---|
to_lower/to_upper/trim | Formats strings | {{ 'ABC' | to_lower}} → abc |
contains/starts_with/ends_with | Match detection | {{ 'abc' | contains 'b'}} → true |
split/join | Split and join | {{ 'a|b|c' | split '|'}} → [a,b,c] |
regex_match/regex_replace | Regular expression operation | {{ 'abc' | regex_replace 'a' 'z'}} → zbc |
to_base64/from_base64 | Base64 conversion | {{ 'abc' | to_base64}} → YWJj |
url_encode/url_decode | URL Conversion | {{ 'a b' | url_encode}} → a%20b |
sha256/md5 | Hashing | {{ 'abc' | sha256}} |
JSON/YAML
| Filter Name | Description | Example |
|---|---|---|
to_json/from_json | JSON Conversion | {{ obj | to_json}}/{{ '{"a":1}' | from_json}} |
to_yaml/from_yaml | YAML Conversion | {{ obj | to_yaml}}/{{ 'a: 1' | from_yaml}} |
ignoreNullsoption allows ignoring null values
Example:{{ obj | to_json { ignoreNulls: true } }}
Date and Time Manipulation
| Filter Name | Description | Example |
|---|---|---|
now/utcnow | Get Current Date and Time | {{ now }} |
add_days/add_hours | Adding Days | {{ '2024-01-01' | add_days 1}} → 2024-01-02 |
format_date | Date Formatting | {{ '2024-01-01' | format_date 'yyyy/MM/dd'}} → 2024/01/01 |
Collection Operations
| Filter Name | Description | Example |
|---|---|---|
sort/reverse | Sort | {{ [3,1,2] | sort}} → [1,2,3] |
unique/flatten | Duplicate Removal/Flattening | {{ [[1,2],[3]] | flatten}} → [1,2,3] |
Path Manipulation
| Filter Name | Description | Example |
|---|---|---|
path_filename/path_basename | Filename Manipulation | {{ '/a/b/file.txt' | path_filename}} → file.txt |
path_join/path_normalize | Path Manipulation | {{ ['a','b','c.txt'] | path_join}} → a/b/c.txt |
path_change_extension | Change extension | {{ '/tmp/data.txt' | path_change_extension '.json'}} → /tmp/data.json |
Utilities
| Filter Name | Description | Example |
|---|---|---|
uuid | Generate UUID | {{ uuid }} → 550e8400-e29b-41d4-a716-446655440000 |
random | Generate random number | {{ random 1 10 }} → 7 |
default/coalesce | Default value processing | {{ null | default 'x'}} → x |
is_null/is_empty | Judgment Filter | {{ '' | is_empty}} → true |
Parameterized Filter Notation
{{ obj | to_json { ignoreNulls: true } }}
Example of Use
# Decode JSON string and extract items
{{ '{"a":1,"b":2}' | from_json | size }} → 2
# Change file extension from file path
{{ '/tmp/data.txt' | path_change_extension '.json' }} → '/tmp/data.json'
# Format the current date and time
{{ now | format_date 'yyyy-MM-dd HH:mm' }}