Chuyển đến nội dung
Skillpedia
Lập trình chung48k · #5272

n8n-expression-syntax

Skill này làm gì

Công cụ này giúp bạn viết và sửa các mã đặc biệt (gọi là 'expression') mà n8n dùng để làm quy trình tự động thông minh hơn. Nó đảm bảo cú pháp đúng để dữ liệu có thể dùng ở nơi cần thiết.

Khi nào nên dùng

  • ✓Khi viết mã để dùng dữ liệu từ một bước trước trong bước khác.
  • ✓Khi bạn gặp lỗi về cú pháp biểu thức.
  • ✓Khi cố dùng thông tin từ webhook hoặc các node khác.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/n8n-expression-syntax/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/n8n-expression-syntax/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Sửa biểu thức này để lấy tên người dùng: {{ $json.body.userName }}”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ kiểm tra xem mã đặc biệt có tuân theo quy tắc của n8n không. Nếu có lỗi thường gặp, nó gợi ý cách sửa để bạn dùng dữ liệu đúng cách trong quy trình.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

n8n Expression Syntax

Expert guide for writing correct n8n expressions in workflows.

Detailed Guide

Read the detailed guide before executing this skill. It retains the complete procedure and reference material. Treat its safety, prerequisites, and validation requirements as mandatory. For focused work, load the relevant sections; for end-to-end work, read the guide completely.

When to Use

  • You need to write or debug n8n expressions using {{ ... }} syntax.
  • The task involves $json, $node, webhook payloads, or expression-related workflow errors.
  • You want syntax-correct dynamic values inside n8n nodes and parameters.

When NOT to Use Expressions

❌ Code Nodes

Code nodes use direct JavaScript access, NOT expressions!

// ❌ WRONG in Code node
const email = '={{$json.email}}';
const name = '{{$json.body.name}}';

// ✅ CORRECT in Code node
const email = $json.email;
const name = $json.body.name;

// Or using Code node API
const email = $input.item.json.email;
const allItems = $input.all();

❌ Webhook Paths

// ❌ WRONG
path: "{{$json.user_id}}/webhook"

// ✅ CORRECT
path: "user-webhook"  // Static paths only

❌ Credential Fields

// ❌ WRONG
apiKey: "={{$env.API_KEY}}"

// ✅ CORRECT
Use n8n credential system, not expressions

Working Examples

For real workflow examples, see EXAMPLES.md

Example 1: Webhook to Slack

Webhook receives:

{
  "body": {
    "name": "John Doe",
    "email": "john@example.com",
    "message": "Hello!"
  }
}

In Slack node text field:

New form submission!

Name: {{$json.body.name}}
Email: {{$json.body.email}}
Message: {{$json.body.message}}

Example 2: HTTP Request to Email

HTTP Request returns:

{
  "data": {
    "items": [
      {"name": "Product 1", "price": 29.99}
    ]
  }
}

In Email node (reference HTTP Request):

Product: {{$node["HTTP Request"].json.data.items[0].name}}
Price: ${{$node["HTTP Request"].json.data.items[0].price}}

Example 3: Format Timestamp

// Current date
{{$now.toFormat('yyyy-MM-dd')}}
// Result: 2025-10-20

// Time
{{$now.toFormat('HH:mm:ss')}}
// Result: 14:30:45

// Full datetime
{{$now.toFormat('yyyy-MM-dd HH:mm')}}
// Result: 2025-10-20 14:30

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
Câu hỏi thường gặp

Expression trong n8n là gì?

Đây là các đoạn mã ngắn dùng cú pháp đặc biệt (như {{ ... }}) để lấy và sử dụng dữ liệu từ các phần khác của quy trình tự động.

Khi nào KHÔNG nên dùng công cụ này?

Đừng dùng nó để viết mã trực tiếp trong 'Code Node', đường dẫn webhook cố định hoặc các trường thông tin xác thực. Cú pháp ở những chỗ đó khác hoặc không được phép.

Làm sao để dùng dữ liệu từ bước trước?

Bạn dùng cú pháp {{ $node["Tên Node"].json["trường"] }} để truy cập dữ liệu từ node trước, hoặc {{ $json["trường"] }} cho dữ liệu nhận trực tiếp.

Chi tiết

Mô tả gốc của tác giả

Validate n8n expression syntax and fix common errors. Use when writing n8n expressions, using {{}} syntax, accessing $json/$node variables, troubleshooting expression errors, or working with webhook data in workflows.

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#5272
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự