Expressions in n8n

작성자

카테고리:

← 피드로
DEV Community · Mohammad Jawad (Kasir) Barati · 2026-08-05 개발(SW)
Cover image for Expressions in n8n

Mohammad Jawad (Kasir) Barati

So here is a list of all the commonly used expressions in n8n with a short description and when you might wanna use them. BTW if you do NOT know what are expressions, they are small pieces of JavaScript-like code wrapped in {{ ... }} that dynamically reference and transform data in your workflows.

Core Data Access Expressions

Expression Description When to Use {{$json}} Accesses the JSON data of the current item When you need to reference the entire data payload of the current workflow item {{$json.fieldName}} Accesses a specific field from the current item To pull a specific value (e.g., {{$json.body.city}} for webhook data) {{$json['field name']}} Accesses a field with spaces or special characters When field names contain spaces, diacritics, or special characters (e.g., {{$json['Gross Price']}}) {{$binary}} Accesses binary data of the current item When working with files, images, or other binary attachments

Referencing Other Nodes

Expression Description When to Use {{$("NodeName").first()}} Gets the first item from a specific node When you need only the first result from a previous node {{$("NodeName").last()}} Gets the last item from a specific node When you need only the last result from a previous node {{$("NodeName").all()}} Gets all items from a specific node When you need to work with the complete output of a previous node {{$("NodeName").item}} Gets the linked item from a specific node When using item linking to trace back the source of data {{$node["HTTP Request"].json.data}} Alternative syntax for referencing other nodes When you prefer bracket notation or when node names have special characters

Date and Time Expressions

Expression Description When to Use {{$now}} Current date and time To timestamp events or calculate time differences {{$today}} Today’s date (start of day) For date-only operations (e.g., filtering by today’s date) {{$now.toFormat("yyyy-MM-dd")}} Formats current date as a string When you need dates in specific formats (e.g., 2026-08-04 for APIs) {{$now.plus({days: 7})}} Adds time to the current date For deadline calculations or future date generation {{DateTime.now().toISO()}} Luxon DateTime to ISO format For standard API date formats

Conditional Expressions

Expression Description When to Use {{$if(condition, "true", "false")}} Returns values based on a condition For simple conditional logic in node parameters {{condition ? true : false}} Ternary operator for conditional logic For inline conditional assignments (more concise than $if) {{$ifEmpty(value, defaultValue)}} Returns default if the first parameter is empty To provide fallback values when data might be missing

String Manipulation

Expression Description When to Use {{text.toUpperCase()}} Converts text to uppercase For standardizing text (e.g., email addresses, codes) {{text.toLowerCase()}} Converts text to lowercase For case-insensitive comparisons or standardization {{text.includes("foo")}} Checks if text contains a specific term For conditional logic based on text content {{text.extractEmail()}} Extracts email addresses from text When you need to parse emails from larger text blocks {{text.trim()}} Removes whitespace from text For cleaning input data before processing {{`Hello ${$json.name}`}} Template literals for string building For constructing dynamic messages or URLs

Array Operations

Expression Description When to Use {{array.length}} Gets the length of an array For conditional checks (e.g., “if items > 0 then…”) {{array.join(", ")}} Joins array elements with a separator To create comma-separated lists from arrays {{array.filter(x => x <= 20)}} Filters array elements based on a condition To extract specific items from a list (e.g., only active users) {{array.map(x => x.id)}} Transforms array elements to new values To extract specific fields (e.g., get all IDs from a user list) {{array.find(x => x.id === 123)}} Finds the first matching element To locate a specific item in a list {{array.slice(0, 5)}} Returns a portion of the array For pagination or limiting results

Math and Number Operations

Expression Description When to Use {{Math.round($json.price * 1.2)}} Rounds a number to the nearest integer For currency calculations or rounding totals {{Math.floor($json.value)}} Rounds a number down to the nearest integer For integer-only operations {{Math.max(...array)}} Gets the maximum value from an array To find the highest value in a dataset {{Math.min(...array)}} Gets the minimum value from an array To find the lowest value in a dataset {{array.reduce((sum, item) => sum + item.amount, 0)}} Summarizes array values For aggregations like total sum or average

Workflow and Environment

Expression Description When to Use {{$env.API_KEY}} Accesses environment variables For using sensitive configuration values (API keys, endpoints) {{$workflow.id}} Accesses current workflow ID For logging or tracking workflow executions {{$execution.id}} Accesses current execution ID For debugging or tracking specific runs {{$execution.mode}} Current execution mode (test/production) For conditional behavior based on how the workflow is run

As you can see they are very much close to what we have in ❤️ JavaScript 😉

You still do NOT believe me? Just look at {{ JSON.stringify(...) }} 😉: https://community.n8n.io/t/output-json-as-string/18356/2

A Concrete Example

{
  "name": "My workflow",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.5,
      "position": [
        -112,
        32
      ],
      "id": "67b01a3f-d92c-4922-b656-b3b065100a6a",
      "name": "Telegram Trigger",
      "webhookId": "63c51c1f-38a1-41ba-9f2b-f7dfc9b2ac57",
      "alwaysOutputData": true,
      "credentials": {
        "telegramApi": {
          "id": "PO7zFfRLA1OdGRSw",
          "name": "Telegram account"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.message.text }}",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        208,
        0
      ],
      "id": "24a3fdfa-d039-48fe-adf9-29196d6ce88e",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "gpt-4o-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        160,
        176
      ],
      "id": "d4cafab9-1e17-44b5-8cef-a68b972833fb",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "1q4kMjpTValhfJZv",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Telegram Trigger').first().json.message.chat.id }}"
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.4,
      "position": [
        320,
        224
      ],
      "id": "70217af4-5c30-4a7a-8cc5-780201420a72",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.dateTimeTool",
      "typeVersion": 2,
      "position": [
        560,
        176
      ],
      "id": "8b2955e9-814e-4e3e-ba91-f596020f237a",
      "name": "Date & Time"
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').first().json.message.chat.id }}",
        "text": "={{ $json.output }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        560,
        0
      ],
      "id": "9f3566f2-6e6e-4734-9b21-2f054d2e9795",
      "name": "Send a text message",
      "webhookId": "cf7ea144-3dc4-4e26-bc48-ee0d1fa4c1d1",
      "credentials": {
        "telegramApi": {
          "id": "I71zFfRLR1OdGRSa",
          "name": "Telegram account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Date & Time": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "0dd12b01-19cc-4f13-95d5-55398a3e84b0",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "e7f40ac67e918c6b77c1db2f31baa37e504a493b4a22e372f2a513b7bf0ca5a1"
  },
  "nodeGroups": [],
  "id": "1bsOs8ssUv4uxhnb",
  "tags": []
}

Enter fullscreen mode Exit fullscreen mode

원문에서 계속 ↗

추출 본문 · 출처: dev.to · https://dev.to/kasir-barati/expressions-in-n8n-537

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다