data/skills/n8n-expression-syntax/EXAMPLES.md
Real working examples from n8n workflows.
Scenario: Form submission webhook posts to Slack
Workflow: Webhook → Slack
Webhook Input (POST):
{
"name": "John Doe",
"email": "[email protected]",
"company": "Acme Corp",
"message": "Interested in your product"
}
Webhook Node Output:
{
"headers": {"content-type": "application/json"},
"params": {},
"query": {},
"body": {
"name": "John Doe",
"email": "[email protected]",
"company": "Acme Corp",
"message": "Interested in your product"
}
}
In Slack Node (text field):
New form submission! 📝
Name: {{$json.body.name}}
Email: {{$json.body.email}}
Company: {{$json.body.company}}
Message: {{$json.body.message}}
Output:
New form submission! 📝
Name: John Doe
Email: [email protected]
Company: Acme Corp
Message: Interested in your product
Scenario: Fetch user data from API and insert into database
Workflow: Schedule → HTTP Request → Postgres
HTTP Request Returns:
{
"data": {
"users": [
{
"id": 123,
"name": "Alice Smith",
"email": "[email protected]",
"role": "admin"
}
]
}
}
In Postgres Node (INSERT statement):
INSERT INTO users (user_id, name, email, role, synced_at)
VALUES (
{{$json.data.users[0].id}},
'{{$json.data.users[0].name}}',
'{{$json.data.users[0].email}}',
'{{$json.data.users[0].role}}',
'{{$now.toFormat('yyyy-MM-dd HH:mm:ss')}}'
)
Result: User inserted with current timestamp
Scenario: Webhook → HTTP Request → Email
Workflow Structure:
Receives:
{
"body": {
"order_id": "ORD-12345"
}
}
URL field:
https://api.example.com/orders/{{$json.body.order_id}}
Returns:
{
"order": {
"id": "ORD-12345",
"customer": "Bob Jones",
"total": 99.99,
"items": ["Widget", "Gadget"]
}
}
Subject:
Order {{$node["Webhook"].json.body.order_id}} Confirmed
Body:
Dear {{$node["HTTP Request"].json.order.customer}},
Your order {{$node["Webhook"].json.body.order_id}} has been confirmed!
Total: ${{$node["HTTP Request"].json.order.total}}
Items: {{$node["HTTP Request"].json.order.items.join(', ')}}
Thank you for your purchase!
Email Result:
Subject: Order ORD-12345 Confirmed
Dear Bob Jones,
Your order ORD-12345 has been confirmed!
Total: $99.99
Items: Widget, Gadget
Thank you for your purchase!
Scenario: Various date format outputs
Current Time: 2025-10-20 14:30:45
{{$now.toISO()}}
Output: 2025-10-20T14:30:45.000Z
{{$now.toFormat('yyyy-MM-dd')}}
Output: 2025-10-20
{{$now.toFormat('HH:mm:ss')}}
Output: 14:30:45
{{$now.toFormat('MMMM dd, yyyy')}}
Output: October 20, 2025
{{$now.plus({days: 7}).toFormat('yyyy-MM-dd')}}
Output: 2025-10-27
{{$now.minus({hours: 24}).toFormat('yyyy-MM-dd HH:mm')}}
Output: 2025-10-19 14:30
Data:
{
"users": [
{"name": "Alice", "email": "[email protected]"},
{"name": "Bob", "email": "[email protected]"},
{"name": "Charlie", "email": "[email protected]"}
]
}
{{$json.users[0].name}}
Output: Alice
{{$json.users[$json.users.length - 1].name}}
Output: Charlie
{{$json.users.map(u => u.email).join(', ')}}
Output: [email protected], [email protected], [email protected]
{{$json.users.length}}
Output: 3
Data:
{
"order": {
"status": "completed",
"total": 150
}
}
{{$json.order.status === 'completed' ? 'Order Complete ✓' : 'Pending...'}}
Output: Order Complete ✓
{{$json.order.notes || 'No notes provided'}}
Output: No notes provided (if notes field doesn't exist)
{{$json.order.total > 100 ? 'Premium Customer' : 'Standard Customer'}}
Output: Premium Customer
Data:
{
"user": {
"email": "[email protected]",
"message": " Hello World "
}
}
{{$json.user.email.toLowerCase()}}
Output: [email protected]
{{$json.user.message.toUpperCase()}}
Output: HELLO WORLD
{{$json.user.message.trim()}}
Output: Hello World
{{$json.user.email.substring(0, 4)}}
Output: JOHN
{{$json.user.message.replace('World', 'n8n')}}
Output: Hello n8n
Data:
{
"user data": {
"first name": "Jane",
"last name": "Doe",
"phone number": "+1234567890"
}
}
{{$json['user data']['first name']}}
Output: Jane
{{$json['user data']['first name']}} {{$json['user data']['last name']}}
Output: Jane Doe
Contact: {{$json['user data']['phone number']}}
Output: Contact: +1234567890
Code Node: Transform webhook data
Input (from Webhook node):
{
"body": {
"items": ["apple", "banana", "cherry"]
}
}
Code (JavaScript):
// ✅ Direct access (no {{ }})
const items = $json.body.items;
// Transform to uppercase
const uppercased = items.map(item => item.toUpperCase());
// Return in n8n format
return [{
json: {
original: items,
transformed: uppercased,
count: items.length
}
}];
Output:
{
"original": ["apple", "banana", "cherry"],
"transformed": ["APPLE", "BANANA", "CHERRY"],
"count": 3
}
Setup: Environment variable API_KEY=secret123
Authorization: Bearer {{$env.API_KEY}}
Result: Authorization: Bearer secret123
https://api.example.com/data?key={{$env.API_KEY}}
Result: https://api.example.com/data?key=secret123
Based on n8n template #2947 (Weather to Slack)
Webhook → OpenStreetMap API → Weather API → Slack
Input: /weather London
Webhook receives:
{
"body": {
"text": "London"
}
}
URL:
https://nominatim.openstreetmap.org/search?q={{$json.body.text}}&format=json
URL:
https://api.weather.gov/points/{{$node["OpenStreetMap"].json[0].lat}},{{$node["OpenStreetMap"].json[0].lon}}
Weather for {{$json.body.text}}:
Temperature: {{$node["Weather API"].json.properties.temperature.value}}°C
Conditions: {{$node["Weather API"].json.properties.shortForecast}}
Key Patterns:
.body{{}} for expressions (except Code nodes)$node["Node Name"].jsonMost Common Uses:
{{$json.body.field}} - Webhook data{{$node["Name"].json.field}} - Other node data{{$now.toFormat('yyyy-MM-dd')}} - Timestamps{{$json.array[0].field}} - Array access{{$json.field || 'default'}} - Default valuesRelated: See COMMON_MISTAKES.md for error examples and fixes.