3. Data Handling and Expressions
The core of n8n workflows is data flow and processing between nodes. You can dynamically manipulate this data using Expressions.
3.1. Data Flow Between Nodes
Each node accepts Input, performs its operation, and then produces Output. The output data is in JSON format and serves as the input for the next node.
// Example output data from a previous node
[
{
"json": {
"id": "1",
"name": "Alice",
"email": "alice@example.com"
}
},
{
"json": {
"id": "2",
"name": "Bob",
"email": "bob@example.com"
}
}
]
3.2. Using Expressions
Expressions are powerful features that allow you to inject dynamic values into data fields. They are enclosed in double curly braces `{{ ... }}`.
- `{{ $json.name }}`: Retrieves the `name` property value from the current node\'s input data.
- `{{ $node["Webhook"].json.email }}`: Retrieves the `email` property value from the output data of the "Webhook" node.
- `{{ $env.MY_API_KEY }}`: Retrieves the value of the environment variable `MY_API_KEY`.
Example: When sending an email using a name received from a "Webhook" node, you can use an expression in the email body like: `Hello {{ $node["Webhook"].json.name }}!`.
3.3. JSON Data Transformation (Set, Item Lists)
Set nodes are used to add, modify, or delete output data. Item Lists nodes are useful for splitting or merging items in an array.
// Using a Set node to add data
{
"json": {
"status": "processed",
"timestamp": "{{ new Date().toISOString() }}"
}
}
Tip: It\'s crucial to run your workflow and check the \'Results\' section of each node to see the actual data flow.