Expression Reference#
These are some commonly used expressions. A more exhaustive list appears below.
| Category | Expression | Description |
|---|---|---|
| Access current input item data | $json |
JSON data of the current item |
$json.fieldName |
Field of the current item | |
$binary |
Binary data of current item | |
| Access previous node data | $("NodeName").first() |
First item in a node |
$("NodeName").item |
Linked item of a node. See Item linking for more information. | |
$("NodeName").all() |
All items of a node | |
$("NodeName").last() |
Last item of a node | |
| Date/Time | $now |
Current date and time |
$today |
Today's date | |
$now.toFormat("yyyy-MM-dd") |
Format current date as a string | |
| Conditionals | $if(condition, "true", "false") |
Helper function that returns a value when a condition is true or false |
condition ? true : false |
Ternary operator: returns one value if a condition is true, another if false | |
$ifEmpty(value, defaultValue) |
Helper function takes two parameters and tests the first to check if it's empty, then returns either the parameter (if not empty) or the second parameter (if the first is empty). The first parameter is empty if it's undefined, null, an empty string '', an array where value.length returns false , or an object where Object.keys(value).length returns false |
|
| String Methods | text.toUpperCase() |
Convert to uppercase |
text.toLowerCase() |
Convert to lowercase | |
text.includes("foo") |
Check if text contains search term | |
text.extractEmail() |
Extract email from text | |
| Array Methods | array.length |
Get array length |
array.join(", ") |
Join array elements using a comma a separator | |
array.filter(x => x <= 20) |
Filter items of array based on the filtering condition | |
array.map(x => x.id) |
Transform items of an array |
Browse the tables below to find methods by the data type on which they act. Click a method name to read detailed documentation for it.
Array#
-
Array.append(elem1, elem2?, ..., elemN?)Adds new elements to the end of the array. Similar to
push(), but returns the modified array. Consider using spread syntax instead (see examples). -
Returns the average of the numbers in the array. Throws an error if there are any non-numbers.
-
Splits the array into an array of sub-arrays, each with the given length
-
Removes any empty values from the array.
null,""andundefinedcount as empty. -
Array.concat(array2, array3?, ... arrayN?)Joins one or more arrays onto the end of the base array
-
Compares two arrays. Returns all elements in the base array that aren't present in
otherArray. -
Array.filter(function(element, index?, array?), thisValue?)Returns an array with only the elements satisfying a condition. The condition is a function that returns
trueorfalse. -
Array.find(function(element, index?, array?), thisValue?)Returns the first element from the array that satisfies the provided condition. The condition is a function that returns
trueorfalse. Returnsundefinedif no matches are found.
If you need all matching elements, use filter().
-
Returns the first element of the array
-
Array.includes(element, start?)Returns
trueif the array contains the specified element -
Array.indexOf(element, start?)Returns the position of the first matching element in the array, or -1 if the element isn’t found. Positions start at 0.
-
Array.intersection(otherArray)Compares two arrays. Returns all elements in the base array that are also present in the other array.
-
Returns
trueif the array has no elements or isnull -
Returns
trueif the array has at least one element -
Merges all elements of the array into a single string, with an optional separator between each element.
The opposite of split().
-
Returns the last element of the array
-
The number of elements in the array
-
Array.map(function(element, index?, array?), thisValue?)Creates a new array by applying a function to each element of the original array
-
Returns the largest number in the array. Throws an error if there are any non-numbers.
-
Returns the smallest number in the array. Throws an error if there are any non-numbers.
-
Array.pluck(fieldName1?, fieldName2?, …)Returns an array containing the values of the given field(s) in each Object of the array. Ignores any array elements that aren’t Objects or don’t have a key matching the field name(s) provided.
-
Returns a randomly-chosen element from the array
-
Array.reduce(function(prevResult, currentElem, currentIndex?, array?), initResult)Reduces an array to a single value by applying a function to each element. The function combines the current element with the result of reducing the previous elements, producing a new result.
-
Removes any re-occurring elements from the array
-
Changes all matching keys (field names) of any Objects in the array. Rename more than one key by adding extra arguments, i.e.
from1, to1, from2, to2, .... -
Reverses the order of the elements in the array
-
Returns a portion of the array, from the
startindex up to (but not including) theendindex. Indexes start at 0. -
Array.smartJoin(keyField, nameField)Creates a single Object from an array of Objects. Each Object in the array provides one field for the returned Object. Each Object in the array must contain a field with the key name and a field with the value.
-
Array.sort(compareFunction(a, b)?)Reorders the elements of the array. For sorting strings alphabetically, no parameter is required. For sorting numbers or Objects, see examples.
-
Returns the total of all the numbers in the array. Throws an error if there are any non-numbers.
-
Converts the array to a JSON string. The same as JavaScript’s
JSON.stringify(). -
Array.toSpliced(start, deleteCount, elem1, ....., elemN)Adds and/or removes array elements at a given position.
See also slice() and append().
-
Converts the array to a string, with values separated by commas. To use a different separator, use
join()instead. -
Concatenates two arrays and then removes any duplicates
-
Removes any duplicate elements from the array
BinaryFile#
-
The path to the directory that the file is stored in. Useful for distinguishing between files with the same name in different directories. Not set if n8n is configured to store files in its database.
-
The suffix attached to the filename (e.g.
txt) -
The name of the file, including extension
-
A string representing the size of the file
-
A string representing the type of the file, e.g.
image. Corresponds to the first part of the MIME type. -
The unique ID of the file. Used to identify the file when it is stored on disk or in a storage service such as S3.
-
A string representing the format of the file’s contents, e.g.
image/jpeg
Boolean#
-
Returns
falsefor all booleans. Returnstruefornull. -
Converts
trueto 1 andfalseto 0 -
Converts
trueto the string ‘true’ andfalseto the string ‘false’
CustomData#
-
$execution.customData.get(key)Returns the custom execution data stored under the given key. More info
-
$execution.customData.getAll()Returns all the key-value pairs of custom data that have been set in the current execution. More info
-
$execution.customData.set(key, value)Stores custom execution data under the key specified. Use this to easily filter executions by this data. More info
-
$execution.customData.setAll(obj)Sets multiple key-value pairs of custom data for the execution. Use this to easily filter executions by this data. More info
Date#
-
Converts a JavaScript Date to a Luxon DateTime. The DateTime contains the same information, but is easier to manipulate.
DateTime#
-
The day of the month (1-31)
-
DateTime.diffTo(otherDateTime, unit)Returns the difference between two DateTimes, in the given unit(s)
-
Returns the difference between the current moment and the DateTime, in the given unit(s). For a textual representation, use
toRelative()instead. -
Rounds the DateTime up to the end of one of its units, e.g. the end of the month
-
Returns
trueif the two DateTimes represent exactly the same moment and are in the same time zone. For a less strict comparison, usehasSame(). -
Extracts a part of the date or time, e.g. the month, as a number. To extract textual names instead, see
format(). -
Converts the DateTime to a string, using the format specified. Formatting guide. For common formats,
toLocaleString()may be easier. -
DateTime.hasSame(otherDateTime, unit)Returns
trueif the two DateTimes are the same, down to the unit specified. Time zones are ignored (only local times are compared), so usetoUTC()first if needed. -
The hour of the day (0-23)
-
DateTime.isBetween(date1, date2)Returns
trueif the DateTime lies between the two moments specified -
Whether the DateTime is in daylight saving time
-
The locale of a DateTime, such 'en-GB'. The locale is used when formatting the DateTime.
-
The millisecond of the second (0-999)
-
Subtracts a given period of time from the DateTime
-
The minute of the hour (0-59)
-
The month (1-12)
-
The textual long month name, e.g. 'October'. Defaults to the system's locale if no locale has been specified.
-
The textual abbreviated month name, e.g. 'Oct'. Defaults to the system's locale if no locale has been specified.
-
Adds a given period of time to the DateTime
-
The quarter of the year (1-4)
-
The second of the minute (0-59)
-
Assigns new values to specified units of the DateTime. To round a DateTime, see also
startOf()andendOf(). -
Sets the locale, which determines the language and formatting for the DateTime. Useful when generating a textual representation of the DateTime, e.g. with
format()ortoLocaleString(). -
Converts the DateTime to the given time zone. The DateTime still represents the same moment unless specified in the options. See also
toLocal()andtoUTC(). -
Rounds the DateTime down to the beginning of one of its units, e.g. the start of the month
-
Returns an ISO 8601-compliant string representation of the DateTime
-
Converts a DateTime to the workflow’s local time zone. The DateTime still represents the same moment unless specified in the parameters. The workflow’s time zone can be set in the workflow settings.
-
DateTime.toLocaleString(formatOpts)Returns a localised string representing the DateTime, i.e. in the language and format corresponding to its locale. Defaults to the system's locale if none specified.
-
Returns a Unix timestamp in milliseconds (the number elapsed since 1st Jan 1970)
-
Returns a textual representation of the time relative to now, e.g. ‘in two days’. Rounds down by default.
-
Returns a Unix timestamp in seconds (the number elapsed since 1st Jan 1970)
-
Returns a string representation of the DateTime. Similar to
toISO(). For more formatting options, seeformat()ortoLocaleString(). -
Converts a DateTime to the UTC time zone. The DateTime still represents the same moment unless specified in the parameters. Use
setZone()to convert to other zones. -
The day of the week. 1 is Monday and 7 is Sunday.
-
The textual long weekday name, e.g. 'Wednesday'. Defaults to the system's locale if no locale has been specified.
-
The textual abbreviated weekday name, e.g. 'Wed'. Defaults to the system's locale if no locale has been specified.
-
The week number of the year (1-52ish)
-
The year
-
The time zone associated with the DateTime
ExecData#
-
Set and get custom execution data (e.g. to filter executions by). You can also do this with the ‘Execution Data’ node. More info
-
The ID of the current workflow execution
-
Can be one of 3 values: either
test(meaning the execution was triggered by clicking a button in n8n) orproduction(meaning the execution was triggered automatically). When running workflow tests,evaluationis used. -
The URL to access a form generated by the ’Wait’ node.
-
The webhook URL to call to resume a workflow waiting at a ’Wait’ node.
HTTPResponse#
-
The body of the response object from the last HTTP call. Only available in the ‘HTTP Request’ node
-
The headers returned by the last HTTP call. Only available in the ‘HTTP Request’ node.
-
The HTTP status code returned by the last HTTP call. Only available in the ‘HTTP Request’ node.
-
An optional message regarding the request status. Only available in the ‘HTTP Request’ node.
Item#
-
Returns any binary data the item contains
-
Returns the JSON data the item contains. More info
NodeInputData#
-
$input.all(branchIndex?, runIndex?)Returns an array of the current node’s input items
-
$input.first(branchIndex?, runIndex?)Returns the current node’s first input item
-
Returns the input item currently being processed
-
$input.last(branchIndex?, runIndex?)Returns the current node’s last input item
-
The configuration settings of the current node. These are the parameters you fill out within the node when configuring it (e.g. its operation).
NodeOutputData#
-
$().all(branchIndex?, runIndex?)Returns an array of the node’s output items
-
$().first(branchIndex?, runIndex?)Returns the first item output by the node
-
Is
trueif the node has executed,falseotherwise -
Returns the matching item, i.e. the one used to produce the current item in the current node. More info
-
$().itemMatching(currentItemIndex?)Returns the matching item, i.e. the one used to produce the item in the current node at the specified index. More info
-
$().last(branchIndex?, runIndex?)Returns the last item output by the node
-
The configuration settings of the given node. These are the parameters you fill out within the node’s UI (e.g. its operation).
Number#
-
Returns the number’s absolute value, i.e. removes any minus sign
-
Rounds the number up to the next whole number
-
Rounds the number down to the nearest whole number
-
Number.format(locale?, options?)Returns a formatted string representing the number. Useful for formatting for a specific language or currency. The same as
Intl.NumberFormat(). -
Returns
falsefor all numbers. Returnstruefornull. -
Returns
trueif the number is even. Throws an error if the number isn’t a whole number. -
Returns
trueif the number is a whole number -
Returns
trueif the number is odd. Throws an error if the number isn’t a whole number. -
Returns the number rounded to the nearest whole number (or specified number of decimal places)
-
Converts the number to a boolean value.
0becomesfalse; everything else becomestrue. -
Converts a numerical timestamp into a DateTime. The format of the timestamp must be specified if it’s not in milliseconds. Uses the time zone in n8n (or in the workflow’s settings).
-
Number.toLocaleString(locales?, options?)Returns a localised string representing the number, i.e. in the language and format corresponding to its locale. Defaults to the system's locale if none specified.
-
Converts the number to a simple textual representation. For more formatting options, see
toLocaleString().
Object#
-
Removes all fields that have empty values, i.e. are
nullor"" -
Returns
trueif there is a field calledname. Only checks top-level keys. Comparison is case-sensitive. -
Returns
trueif the Object has no keys (fields) set or isnull -
Returns
trueif the Object has at least one key (field) set -
Object.keepFieldsContaining(value)Removes any fields whose values don’t at least partly match the given
value. Comparison is case-sensitive. Fields that aren’t strings will always be removed. -
Returns an array with all the field names (keys) the object contains. The same as JavaScript’s
Object.keys(obj). -
Merges the two Objects into a single one. If a key (field name) exists in both Objects, the value from the first (base) Object is used.
-
Removes a field from the Object. The same as JavaScript’s
delete. -
Object.removeFieldsContaining(value)Removes keys (fields) whose values at least partly match the given
value. Comparison is case-sensitive. Fields that aren’t strings are always kept. -
Converts the Object to a JSON string. Similar to JavaScript’s
JSON.stringify(). -
Generates a URL parameter string from the Object’s keys and values. Only top-level keys are supported.
-
Returns an array with all the values of the fields the Object contains. The same as JavaScript’s
Object.values(obj).
PrevNodeData#
-
The name of the node that the current input came from.
Always uses the current node’s first input connector if there is more than one (e.g. in the ‘Merge’ node).
-
The index of the output connector that the current input came from. Use this when the previous node had multiple outputs (such as an ‘If’ or ‘Switch’ node).
Always uses the current node’s first input connector if there is more than one (e.g. in the ‘Merge’ node).
-
The run of the previous node that generated the current input.
Always uses the current node’s first input connector if there is more than one (e.g. in the ‘Merge’ node).
Root#
-
Returns the data of the specified node
-
Returns any binary input data to the current node, for the current item. Shorthand for
$input.item.binary. -
Retrieve or set metadata for the current execution
-
$fromAI(key, description?, type?, defaultValue?)Use when a large language model should provide the value of a node parameter. Consider providing a description for better results.
-
$if(condition, valueIfTrue, valueIfFalse)Returns one of two values depending on the
condition. Similar to the?operator in JavaScript. -
Returns the first parameter if it isn’t empty, otherwise returns the second parameter. The following count as empty:
””,[],{},null,undefined -
The input data of the current node
-
The position of the item currently being processed in the list of input items
-
Extracts data from an object (or array of objects) using a JMESPath expression. Useful for querying complex, nested objects. Returns
undefinedif the expression is invalid. -
Returns the JSON input data to the current node, for the current item. Shorthand for
$input.item.json. More info -
Returns the highest of the given numbers
-
Returns the lowest of the given numbers
-
The version of the current node (as displayed at the bottom of the nodes’s settings pane)
-
A DateTime representing the current moment.
Uses the workflow’s time zone (which can be changed in the workflow settings).
-
The number of results pages the node has fetched. Only available in the ‘HTTP Request’ node.
-
The configuration settings of the current node. These are the parameters you fill out within the node’s UI (e.g. its operation).
-
Information about the node that the current input came from.
When in a ‘Merge’ node, always uses the first input connector.
-
The request object sent during the last run of the node. Only available in the ‘HTTP Request’ node.
-
The response returned by the last HTTP call. Only available in the ‘HTTP Request’ node.
-
The index of the current run of the current node execution. Starts at 0.
-
The secrets from an external secrets vault, if configured. Secret values are never displayed to the user. Only available in credential fields.
-
A DateTime representing midnight at the start of the current day.
Uses the instance’s time zone (unless overridden in the workflow’s settings).
String#
-
Converts plain text to a base64-encoded string
-
Converts a base64-encoded string to plain text
-
String.concat(string1, string2?, ..., stringN?)Joins one or more strings onto the end of the base string. Alternatively, use the
+operator (see examples). -
If the string is an email address or URL, returns its domain (or
undefinedif nothing found).
If the string also contains other content, try using extractEmail() or extractUrl() first.
-
Extracts the first email found in the string. Returns
undefinedif none is found. -
Extracts the first URL found in the string. Returns
undefinedif none is found. Only recognizes full URLs, e.g. those starting withhttp. -
Returns the part of a URL after the domain, or
undefinedif no URL found.
If the string also contains other content, try using extractUrl() first.
-
Returns the string hashed with the given algorithm. Defaults to md5 if not specified.
-
String.includes(searchString, start?)Returns
trueif the string contains thesearchString. Case-sensitive. -
String.indexOf(searchString, start?)Returns the index (position) of the first occurrence of
searchStringwithin the base string, or -1 if not found. Case-sensitive. -
Returns
trueif the string is a domain -
Returns
trueif the string is an email -
Returns
trueif the string has no characters or isnull -
Returns
trueif the string has at least one character -
Returns
trueif the string represents a number -
Returns
trueif the string is a valid URL -
The number of characters in the string
-
Matches the string against a regular expression. Returns an array containing the first match, or all matches if the
gflag is set in the regular expression. Returnsnullif no matches are found.
For checking whether text is present, consider includes() instead.
-
Returns the JavaScript Object or value represented by the string, or
undefinedif the string isn’t valid JSON. Single-quoted JSON is not supported. -
Wraps a string in quotation marks, and escapes any quotation marks already in the string. Useful when constructing JSON, SQL, etc.
-
Removes any Markdown formatting from the string. Also removes HTML tags.
-
Removes tags, such as HTML or XML, from the string
-
String.replace(pattern, replacement)Returns a string with the first occurrence of
patternreplaced byreplacement.
To replace all occurrences, use replaceAll() instead.
-
String.replaceAll(pattern, replacement)Returns a string with all occurrences of
patternreplaced byreplacement -
Replaces special characters in the string with the closest ASCII character
-
Returns the index (position) of the first occurrence of a pattern within the string, or -1 if not found. The pattern is specified using a regular expression. To use text instead, see
indexOf(). -
Extracts a fragment of the string at the given position. For more advanced extraction, see
match(). -
String.split(separator?, limit?)Splits the string into an array of substrings. Each split is made at the
separator, and the separator isn’t included in the output.
The opposite of using join() on an array.
-
String.startsWith(searchString, start?)Returns
trueif the string starts withsearchString. Case-sensitive. -
Extracts a fragment of the string at the given position. For more advanced extraction, see
match(). -
Converts the string to a boolean value.
0,falseandnoresolve tofalse, everything else totrue. Case-insensitive. -
Converts the string to a DateTime. Useful for further transformation. Supported formats for the string are ISO 8601, HTTP, RFC2822, SQL and Unix timestamp in milliseconds.
To parse other formats, use DateTime.fromFormat().
-
Prepares the string to be inserted into a JSON object. Escapes any quotes and special characters (e.g. new lines), and wraps the string in quotes.
The same as JavaScript’s JSON.stringify().
-
Converts all letters in the string to lower case
-
Converts a string representing a number to a number. Throws an error if the string doesn’t start with a valid number.
-
Changes the capitalization of the string to sentence case. The first letter of each sentence is capitalized and all others are lowercased.
-
Changes the format of the string to snake case. Spaces and dashes are replaced by
_, symbols are removed and all letters are lowercased. -
Changes the capitalization of the string to title case. The first letter of each word is capitalized and the others left unchanged. Short prepositions and conjunctions aren’t capitalized (e.g. ‘a’, ‘the’).
-
Converts all letters in the string to upper case (capitals)
-
Removes whitespace from both ends of the string. Whitespace includes new lines, tabs, spaces, etc.
-
Decodes a URL-encoded string. Replaces any character codes in the form of
%XXwith their corresponding characters. -
Encodes the string so that it can be used in a URL. Spaces and special characters are replaced with codes of the form
%XX.
WorkflowData#
-
Whether the workflow is active
-
The workflow ID. Can also be found in the workflow’s URL.
-
The name of the workflow, as shown at the top of the editor