构建工作流
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
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, "" and undefined count as empty.
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.
Returns an array with only the elements satisfying a condition. The condition is a function that returns true or false.
Returns the first element from the array that satisfies the provided condition. The condition is a function that returns true or false. Returns undefined if no matches are found.
If you need all matching elements, use filter().
Returns the first element of the array
Returns true if the array contains the specified element
Returns the position of the first matching element in the array, or -1 if the element isn’t found. Positions start at 0.
Compares two arrays. Returns all elements in the base array that are also present in the other array.
Returns true if the array has no elements or is null
Returns true if 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
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.
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
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 start index up to (but not including) the end index. Indexes start at 0.
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.
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().
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 false for all booleans. Returns true for null.
Converts true to 1 and false to 0
Converts true to the string ‘true’ and false to the string ‘false’
CustomData
Returns the custom execution data stored under the given key. More info
Returns all the key-value pairs of custom data that have been set in the current execution. More info
Stores custom execution data under the key specified. Use this to easily filter executions by this data. More info
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)
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 true if the two DateTimes represent exactly the same moment and are in the same time zone. For a less strict comparison, use hasSame().
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.
Returns true if the two DateTimes are the same, down to the unit specified. Time zones are ignored (only local times are compared), so use toUTC() first if needed.
The hour of the day (0-23)
Returns true if 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() and endOf().
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() or toLocaleString().
Converts the DateTime to the given time zone. The DateTime still represents the same moment unless specified in the options. See also toLocal() and toUTC().
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.
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, see format() or toLocaleString().
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) or production (meaning the execution was triggered automatically). When running workflow tests, evaluation is 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
Returns an array of the current node’s input items
Returns the current node’s first input item
Returns the input item currently being processed
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
Returns an array of the node’s output items
Returns the first item output by the node
Is true if the node has executed, false otherwise
Returns the matching item, i.e. the one used to produce the current item in the current node. More info
Returns the matching item, i.e. the one used to produce the item in the current node at the specified index. More info
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
Returns a formatted string representing the number. Useful for formatting for a specific language or currency. The same as \<a href=”https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\\\_Objects/Intl/NumberFormat/NumberFormat”>\Intl.NumberFormat()\.
Returns false for all numbers. Returns true for null.
Returns true if the number is even. Throws an error if the number isn’t a whole number.
Returns true if the number is a whole number
Returns true if 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. 0 becomes false; everything else becomes true.
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).
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 null or ""
Returns true if there is a field called name. Only checks top-level keys. Comparison is case-sensitive.
Returns true if the Object has no keys (fields) set or is null
Returns true if the Object has at least one key (field) set
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.
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
Use when a large language model should provide the value of a node parameter. Consider providing a description for better results.
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 \<a href=”/code/cookbook/jmespath/”>JMESPath expression. Useful for querying complex, nested objects. Returns undefined if 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).
The variables available to the workflow
Information about the current workflow
String
Converts plain text to a base64-encoded string
Converts a base64-encoded string to plain text
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 undefined if nothing found).
If the string also contains other content, try using extractEmail() or extractUrl() first.
Extracts the first email found in the string. Returns undefined if none is found.
Extracts the first URL found in the string. Returns undefined if none is found. Only recognizes full URLs, e.g. those starting with http.
Returns the part of a URL after the domain, or undefined if 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.
Returns true if the string contains the searchString. Case-sensitive.
Returns the index (position) of the first occurrence of searchString within the base string, or -1 if not found. Case-sensitive.
Returns true if the string is a domain
Returns true if the string is an email
Returns true if the string has no characters or is null
Returns true if the string has at least one character
Returns true if the string represents a number
Returns true if the string is a valid URL
The number of characters in the string
Matches the string against a \<a href=”https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular\\\_expressions”>regular expression. Returns an array containing the first match, or all matches if the g flag is set in the regular expression. Returns null if no matches are found.
For checking whether text is present, consider includes() instead.
Returns the JavaScript Object or value represented by the string, or undefined if 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
Returns a string with the first occurrence of pattern replaced by replacement.
To replace all occurrences, use replaceAll() instead.
Returns a string with all occurrences of pattern replaced by replacement
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 \<a href=”https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular\\\_expressions”>regular expression. To use text instead, see indexOf().
Extracts a fragment of the string at the given position. For more advanced extraction, see match().
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.
Returns true if the string starts with searchString. 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, false and no resolve to false, everything else to true. 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 \<a href=”https://moment.github.io/luxon/api-docs/index.html#datetimefromformat”> 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 %XX with 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
官方原文和授权
本页来自 N8N 英文官方网站固定快照,并转换成 xueai 静态页面。内容以 N8N 持续更新的官方页面为准。