DEV Community

Cover image for Expressions in n8n

Expressions in n8n

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": "0f3d0681-659d-4b4f-bade-1c3ba7a294e4",
      "name": "Telegram Trigger",
      "webhookId": "c9492258-6588-4dc7-a6e1-87b83bf4554f",
      "alwaysOutputData": true,
      "credentials": {
        "telegramApi": {
          "id": "IO7zFfRLA1OdGRSd",
          "name": "Telegram account"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.message.text }}",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        208,
        0
      ],
      "id": "4934adaa-9139-4359-a1d5-78f241de4cd9",
      "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": "883244c8-0ad6-4f80-a985-bcbd3a566287",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "0h4kMjpTValhfJZv",
          "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": "e30d43c6-b7df-4467-a515-847f3a8c75d1",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.dateTimeTool",
      "typeVersion": 2,
      "position": [
        560,
        176
      ],
      "id": "e87c126c-01cf-4750-b322-28404c5257ce",
      "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": "2995c7a3-b5c6-4328-b47e-24da741d93f6",
      "name": "Send a text message",
      "webhookId": "2f9e60d8-23f7-4ac0-b9a2-2d6ce2cacb57",
      "credentials": {
        "telegramApi": {
          "id": "IO7zFfRLA1OdGRSd",
          "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": "4f8e5311-d767-4eda-b148-0302e5eb3480",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "d7f40ac67c918c6b77c1db2f31baa37e504a493b4a22e372f2a513b7bf0ca5a9"
  },
  "nodeGroups": [],
  "id": "6bsOs8ssUv4uxhna",
  "tags": []
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)