Back to Curriculum

Data Mapping and JS Expressions: The Logic Layer

In 2026, the power of n8n lies in its ability to manipulate data between nodes using JavaScript expressions. This lesson teaches you how to transform raw JSON payloads into clean, actionable variables for your growth engine.

🏗️ The Expression Syntax

n8n uses a template-string-like syntax to access data from previous nodes.

  • Accessing Data: {{ $node["NodeName"].json["field_name"] }}
  • Accessing Parameters: {{ $node["NodeName"].parameter["param_name"] }}

🛠️ Technical Snippet: High-Fidelity JS Expressions

Common data transformations you will use:

// 1. Normalize a phone number to E.164 format
{{ $json.phone.replace(/[^0-9]/g, '').replace(/^0/, '+92') }}

// 2. Conditional text based on lead score
{{ $json.score > 8 ? "Priority Lead" : "Standard Lead" }}

// 3. Extracting the domain from an email
{{ $json.email.split('@')[1] }}

🔍 Nuance: The 'Binary' vs 'JSON' Data

n8n distinguishes between JSON data (text/numbers) and Binary data (files/images). When mapping an AI-generated report to an email node, you must ensure you are referencing the json key, not the binary output.


⚡ Practice Lab: The Data Transformer

  1. Trigger: Create a "Manual Trigger" with a JSON payload containing a messy name (e.g., " taqi NAQVI ").
  2. Transform: Use a "Set" node with a JS expression to trim the whitespace and convert it to Title Case.
  3. Result: Verify the output is clean and professional.

📝 Homework: The Revenue Calculator

Create a workflow that takes a "Deal Size" and a "Closing Probability" (0-1). Use a JS expression to calculate the "Expected Value" and format it as a currency string (e.g., "$5,000").