惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
F
Fortinet All Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 叶小钗
爱范儿
爱范儿
美团技术团队
H
Hackread – Cybersecurity News, Data Breaches, AI and More
有赞技术团队
有赞技术团队
博客园_首页
T
The Blog of Author Tim Ferriss
T
Tailwind CSS Blog
V
Visual Studio Blog
Jina AI
Jina AI
博客园 - Franky
量子位
MongoDB | Blog
MongoDB | Blog
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
aimingoo的专栏
aimingoo的专栏
M
MIT News - Artificial intelligence

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
n8n Expressions: How to Use Dynamic Data in Your Workflow...
Pirate Prentice · 2026-06-28 · via DEV Community

Pirate Prentice

If you have ever copy-pasted the same value into a dozen nodes, you already know the pain. n8n expressions are the fix. They let you pull live data from any previous node, do math, format dates, and build strings in any field in your workflow.

This post covers everything you need to get moving: syntax, the most useful built-in variables, and real-world examples you can drop into your own workflows.


What Is an n8n Expression?

An expression is JavaScript wrapped in double curly braces.
Whenever n8n sees those braces in a field, it evaluates what is inside and uses the result.

Example: {{ $json.email }} grabs the email field from the current item. No node. No extra step. Just live data.


How to Open the Expression Editor

  1. Hover over any input field in a node.
  2. Click the = icon that appears on the right.
  3. The field turns purple, you are now in expression mode.
  4. Type your expression. The preview pane at the bottom shows the live result.

The Core Variables

$json - current item data

  • $json.name - simple field
  • $json.order.total - nested field
  • $json.items[0].sku - array element

$json is the data object of the current item being processed.

$('Node Name').item.json - data from a specific node

Pull data from any previous node by name. This is the most powerful pattern.

Example: $('HTTP Request').item.json.id or $('Get User').item.json.profile.avatar_url

$now - current timestamp (Luxon DateTime)

  • $now.toISO() - full ISO string
  • $now.toFormat('yyyy-MM-dd') - formatted date
  • $now.minus({ days: 7 }).toISO() - one week ago

$vars - workflow variables (n8n 1.x+)

Set static values once in Settings > Variables and reference them everywhere.

  • $vars.SLACK_CHANNEL
  • $vars.API_BASE_URL

$env - environment variables (self-hosted only)

  • $env.MY_SECRET_KEY

JavaScript Is Fair Game

Everything inside {{ }} is evaluated as JavaScript:

// String methods
{{ $json.name.toUpperCase() }}
{{ $json.email.split('@')[0] }}

// Ternary
{{ $json.status === 'active' ? 'Active' : 'Inactive' }}

// Math
{{ $json.price * 1.2 }}

// Array length
{{ $json.items.length }}


Practical Examples

1. Dynamic email subject

Order confirmed for {{ $json.customer_name }}

2. Format date for Google Sheets

{{ $now.toFormat('MM/dd/yyyy') }}

3. Combine names

{{ $json.first_name + ' ' + $json.last_name }}

4. Safely handle a missing field

{{ $json.middle_name ?? 'N/A' }}

The ?? nullish coalescing operator returns N/A if the field is null or undefined.

5. Pull data from a different branch

In a Merge node after two parallel branches:

Customer: {{ $('Get Customer').item.json.name }}
Order total: {{ $('Get Order').item.json.total }}

6. Build a URL dynamically

https://api.example.com/users/{{ $json.user_id }}/orders/{{ $json.order_id }}

Paste directly into the URL field of an HTTP Request node.


Common Mistakes

Mistake Fix
json.name missing $ Use $json.name
Spaces inside braces {{ $json.name }} not { {$json.name} }
Wrong node name casing Names are case-sensitive
Array without index Use $json.items[0] not $json.items
Expression in static field Click = icon to switch to expression mode

Free Workflow JSON

Here is a minimal workflow demonstrating four expression patterns - dynamic URL, formatted date, ternary condition, and name concat:

{
  "name": "n8n Expressions Demo",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [240, 300]
    },
    {
      "parameters": {
        "values": {
          "string": [
            { "name": "user_id", "value": "42" },
            { "name": "status", "value": "active" },
            { "name": "first_name", "value": "Ada" },
            { "name": "last_name", "value": "Lovelace" }
          ]
        }
      },
      "name": "Set Sample Data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [460, 300]
    },
    {
      "parameters": {
        "values": {
          "string": [
            { "name": "full_name", "value": "={{ $json.first_name + ' ' + $json.last_name }}" },
            { "name": "api_url", "value": "=https://api.example.com/users/{{ $json.user_id }}" },
            { "name": "label", "value": "={{ $json.status === 'active' ? 'Active' : 'Inactive' }}" },
            { "name": "today", "value": "={{ $now.toFormat('yyyy-MM-dd') }}" }
          ]
        }
      },
      "name": "Build Expressions",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [680, 300]
    }
  ],
  "connections": {
    "Start": { "main": [[{ "node": "Set Sample Data", "type": "main", "index": 0 }]] },
    "Set Sample Data": { "main": [[{ "node": "Build Expressions", "type": "main", "index": 0 }]] }
  }
}

Import it into n8n, run it once, and inspect the output of Build Expressions to see all four patterns live.


Want More Ready-to-Run Workflows?

The patterns above power every automation I build. If you want a full library of production-ready workflows - error handling, webhooks, Stripe receipts, CRM sync, and more - I packaged them into the n8n Workflow Starter Pack ($29).

One purchase, instant download, no subscription.


Quick Reference

Variable What it gives you
$json.field Field from the current item
$('Node Name').item.json.field Field from a named previous node
$now Current time (Luxon DateTime)
$vars.NAME Workflow variable
$env.NAME Environment variable (self-hosted)
$input.all() All items entering the current node
$input.first().json First item only
$input.last().json Last item only

Expressions unlock the difference between a rigid script and a truly dynamic workflow. Once they click, you will use them in every single node.

Drop a question below if you get stuck on a specific expression - happy to help debug it.