Torq supports a wide range of Sprig functions (Golang templates), providing powerful built-in utilities for string manipulation, data formatting, logic operations, and date/time handling. These functions let you transform, calculate, and validate data directly within your workflows.
Date and time
The table below highlights the most commonly used Sprig date and time functions available in Torq.
Function | Description | Example > Output |
|
|
|
| Returns the Unix timestamp (seconds since January 1 1970 UTC) for a given date or for the current time |
|
| Calculates how much time has passed since the provided timestamp and returns a human-readable duration |
|
| Parses a date string and converts it into a timestamp object that other time functions can use |
|
| Converts a timestamp into a specific timezone, useful for aligning logs or reports |
|
| Adds or subtracts a duration (like hours, days, or minutes) from a given date or timestamp |
|
| Converts a duration string into a precise duration value usable in time calculations |
|
| Rounds a duration to the nearest unit (e.g., minute, hour, day) for cleaner output or scheduling precision |
|
| Returns the current time as a Unix timestamp (seconds since Jan 1, 1970) |
|
| Returns the current time as a Unix timestamp in milliseconds, microseconds, or nanoseconds |
|
| Returns the current year or the current day of the month as an integer |
|
| Returns the current month or the current day of the week as a string |
|
Date and time formatting in Sprig
Sprig supports Go’s native time formatting system. The tables below list common date and time format tokens and predefined layouts that you can use in Torq.
Date and time
Function | Example |
Year |
|
Month |
|
Day of the week |
|
Day of the month |
|
Day of the year |
|
Hour |
|
Minute |
|
Second |
|
AM/PM mark |
|
Layout
Function | Example |
Layout |
|
ANSIC |
|
UnixDate |
|
RubyDate |
|
RFC822 |
|
RFC822Z |
|
RFC850 |
|
RFC1123 |
|
RFC1123Z |
|
RFC3339 |
|
RFC3339Nano |
|
Kitchen |
|
Timestamps
Function | Example |
Stamp |
|
StampMilli |
|
StampMicro |
|
StampNano |
|
DateTime |
|
DateOnly |
|
TimeOnly |
|
Base64
Encode and decode data into a text format that can be transmitted or stored without corruption.
Function | Description | Example > Output |
| Encodes or decodes the provided data using Base64 encoding |
|
Default
Handle missing or undefined values gracefully by providing a default alternative.
Function | Description | Example > Output |
| If the evaluated value is empty, the given default will be returned |
|
Conditional and logic functions
Control logic flow and handle conditions dynamically inside templates.
Function | Description | Example > Output |
| Takes two values and a third test value. If the test value is true, the first of the two values will be returned. If the test value is empty, the second of the two values will be returned. |
|
| Returns |
|
Data conversion and formatting
Convert data types and structures between strings, numbers, and JSON to ensure compatibility across workflow steps or API calls.
Function | Description | Example > Output |
| Escapes a string so it can be safely embedded in JSON (adds backslashes for quotes, newlines, etc.) | |
| Converts a data structure (e.g., map, list, dict) into a JSON string. Useful for serializing data for API requests or logs. |
|
| Converts a data structure (e.g., map, list, dict) into an indented, human-readable JSON format for easier viewing |
|
| Similar to |
|
| Converts the provided data to an integer or to a string |
|
| Converts each element of a list to a string |
|
String manipulation
Transform and manage strings for better data handling: splitting, joining, and structuring text as needed.
Function | Description | Example > Output |
| Joins elements of an array or list into a single string, using the given separator |
|
| Splits a string into a list of substrings based on a separator |
|
| Splits a string or list into smaller lists using a separator |
|
| Splits a string into n parts using a separator, returning only up to the specified number of splits |
|
List
Create, modify, and inspect lists (arrays). They’re essential for managing collections of data, such as lists of observables, user emails, or alert types.
Add | toJson when you want the output to appear as readable or transferable JSON text rather than a raw object.
Function | Description | Example > Output |
| Creates a new list (array) from the provided items. Useful for grouping multiple values together. |
|
| Returns all elements of a list except the first |
|
| Checks whether a list or map contains a given value or key. Returns |
|
| Adds one or more elements to the end of a list and returns the new list |
|
| Adds one or more elements to the beginning of a list and returns the new list |
|
| Removes duplicate values from a list |
|
| Returns a list that excludes specified values |
|
| Extracts a sub-list (slice) from the given list using start and end indexes |
|
| Returns the last element of a list |
|
| Returns the first element of a list |
|
| Returns all elements of a list except the last one |
|
| Combines two or more maps (key-value pairs) into one. Later values overwrite earlier ones. |
|
| Returns the length of a string, array, map, or object |
|
Dictionary
Create and manipulate key-value pairs, similar to JSON objects or Python dictionaries.
Add | toJson when you want the output to appear as readable or transferable JSON text rather than a raw object.
Function | Description | Example > Output |
| Creates a new dictionary (map) with the specified key-value pairs. Useful for grouping structured data. |
|
| Returns a list of all keys in a dictionary |
|
| Returns a list of all values in a dictionary |
|
| Adds or updates a key-value pair in an existing dictionary. Returns the updated dictionary. |
|
| Removes a key (and its value) from a dictionary. Returns the updated dictionary |
|
| Checks whether a dictionary contains a specific key. Returns |
|
| Combines two or more maps (key-value pairs) into one. Later values overwrite earlier ones. |
|
String
Format, clean, and manipulate text values inside Torq workflows.
Function | Description | Example > Output |
|
|
|
| Converts a string to uppercase or lowercase |
|
| Converts the first letter of each word in a string to uppercase. Useful for formatting names, titles, or headings. |
|
| Converts all characters in a string to lowercase. Often used for normalization before comparison or storage. |
|
| Returns a substring from a provided string using start and end indexes |
|
| Removes all whitespaces from a string |
|
| Truncates a string by keeping the first X characters |
|
| Returns |
|
| Returns |
|
| Replaces all occurrences of a substring within a string |
|
| Converts strings to |
|
| Wraps text by inserting the specified string (such as a tab or symbol) after the defined number of characters |
|
| Wraps text by inserting a newline after the specified number of characters |
|
Regex
Search, match, and manipulate strings inside templates.
Function | Description | Example > Output |
| Checks whether a given string matches a regular expression pattern. Returns |
|
| Returns the first substring that matches the given regular expression pattern |
|
| Returns substrings that match the given regular expression pattern as an array. Use an additional numeric argument (e.g., |
|
| Replaces all substrings that match a given regular expression with a specified replacement string |
|
| Splits a string into a list based on matches of a regular expression. Use an additional numeric argument (e.g., |
|
Integer math
Perform integer-based calculations.
Function | Description | Example > Output |
| Performs addition, subtraction, multiplication, or division. Requires numeric values (not strings). |
|
| Increments a numeric value by 1. Useful for counters and iterative operations. |
|
| Returns the remainder of a division operation (modulus) |
|
| Returns the highest value among the provided numbers |
|
| Returns the lowest value among the provided numbers |
|
| Rounds a floating-point number down to the nearest integer |
|
| Rounds a floating-point number up to the nearest integer |
|
| Rounds a floating-point number to the nearest integer or to a specified precision (half values round up). |
|
Handling errors when using inline Golang functions
When using inline Golang functions such as jsonEscape, replace, or lower with dynamic input that isn’t under your control, the input may interfere with Go template parsing and cause the inline function to fail, resulting in an error similar to one of the following:
evaluating exit step success template (3): error parsing template: 1:18628: function "trimprefix" not defined
or
failed evaluating env at key "VALUE_STRING". unexpected "," in operand (3): error parsing template: 1:13: unexpected "," in operand
If you encounter these errors, you can move the logic from the inline Golang function into a dedicated utility step, such as:
Escape JSON String
Replace in String
Escape Curly Brackets
