DEV Community

Robert Breen
Robert Breen

Posted on Originally published at ynteractive.com

n8n Items and Expressions: Five Invoices In, Five Reminders Out (Pinned Mock Data, $json and .round(2))

Most people who get stuck in n8n are not stuck on a node. They are stuck on the data between nodes: what an "item" is, why {{ $json.client }} sometimes works and sometimes shows nothing, and why a simple percentage turns into 15.200000000000001.

This walkthrough fixes that with one small example. A made-up bookkeeping firm, Clearview Bookkeeping, has five overdue invoices and writes every reminder by hand. Before automating the email, you need to see how n8n holds the data. You will:

  1. Pin five fake invoices on a manual trigger, no real app connected.
  2. Read them as Schema, Table and JSON.
  3. Build one Edit Fields (Set) node that produces a reminder sentence, an email field and a 2% late fee for every invoice.

Step 1: Give the trigger test data with "set mock data"

Start an empty workflow, click Add first step..., and choose Trigger manually. While you are learning, a button is the easiest way to start.

Open the trigger (it sits on the canvas as When clicking 'Execute workflow'). It has no parameters and the OUTPUT says No trigger output. Instead of connecting a real system, click set mock data. The EDIT OUTPUT box holds an example; replace it with this list and click Save:

[
  {"client":"Lakeside Dental","email":"billing@lakeside-dental.example","invoice":"INV-1042","amount":480,"days_late":12},
  {"client":"Northpoint Realty","email":"ap@northpoint.example","invoice":"INV-1045","amount":1250,"days_late":34},
  {"client":"Brightline Studio","email":"hello@brightline.example","invoice":"INV-1047","amount":300,"days_late":5},
  {"client":"Cedar & Vine Law","email":"office@cedarvine.example","invoice":"INV-1051","amount":2100,"days_late":48},
  {"client":"Harbor Lane Marketing","email":"finance@harborlane.example","invoice":"INV-1053","amount":760,"days_late":19}
]
Enter fullscreen mode Exit fullscreen mode

A list in square brackets, one pair of curly brackets per invoice. The email addresses use .example domains, so nothing can be sent by accident.

After saving, a banner reads This data is pinned for test executions, and the OUTPUT says 5 items. Test runs now reuse this data instead of calling a real app, which is also how you avoid burning API calls while building.

Step 2: One item per record, read three ways

n8n passes a list of items between nodes. Each item is one record with named fields, and most nodes run once per item: 5 invoices in, 5 results out.

Switch the OUTPUT view to see the same items three ways:

  • Schema shows the fields of one item.
  • Table shows five rows, one per invoice. Text fields carry a T, numbers a #.
  • JSON shows the raw data, exactly as you pasted it. Almost every app sends data to n8n in this shape.

Close the node. The pin icon on the trigger reminds you it is using pinned data.

Step 3: Write expressions by dragging

Click the + after the trigger, type Edit, and pick Edit Fields (Set). The INPUT panel shows 5 items and the fields of the first one.

Click Add Field, name it reminder, then drag client from INPUT onto the value box. n8n writes:

{{ $json.client }}
Enter fullscreen mode Exit fullscreen mode

$json means this item's data, so the expression reads "this item's client". Now type is (a space each side), drag in days_late, and finish with days late. The value becomes:

{{ $json.client }} is {{ $json.days_late }} days late
Enter fullscreen mode Exit fullscreen mode

The Result line under the field shows Lakeside Dental is 12 days late for Item 0. Click the › next to it to preview Item 1: Northpoint Realty is 34 days late. One expression, a different answer for every item. That is the whole idea of items.

Shortcut: drop a whole field

Drag email onto the Drag input fields here area. n8n creates a field named email with the value {{ $json.email }} in one move. Use this when you want to carry a field through unchanged.

Step 4: A calculated field, and the two gotchas

Click Add Field again and name it late_fee. A fee is a number, so open the type box (it says String) and choose Number.

Gotcha 1: a Number box only takes digits. If you type a {{ }} formula straight into it, the field strips everything that is not a digit and mangles it. Point at the value and click Expression first, then paste:

{{ ($json.amount * 0.02).round(2) }}
Enter fullscreen mode Exit fullscreen mode

Anything inside {{ }} is JavaScript, so this is 2% of the amount.

Gotcha 2: floating point. Without .round(2), Harbor Lane's 760 * 0.02 shows as 15.200000000000001. Computers store decimals in binary, so some results carry a long tail. .round(2) rounds to cents.

Click Execute step. You get 5 items in and 5 items out, each with its own reminder, email and late_fee. The fees come out as:

invoice amount late_fee
INV-1042 480 9.6
INV-1045 1250 25
INV-1047 300 6
INV-1051 2100 42
INV-1053 760 15.2

What the output looks like as JSON

Switch the Edit Fields OUTPUT to JSON and the first item looks like this (shape only; your field order may differ, and Edit Fields keeps only the fields you set unless you include the others):

{
  "reminder": "Lakeside Dental is 12 days late",
  "email": "billing@lakeside-dental.example",
  "late_fee": 9.6
}
Enter fullscreen mode Exit fullscreen mode

That is a clean record, ready for a Gmail or Slack node downstream, which will also run once per item.

Checklist

  • [ ] Trigger has pinned mock data and the banner says This data is pinned for test executions
  • [ ] OUTPUT shows 5 items in Table view
  • [ ] reminder uses {{ $json.client }} and {{ $json.days_late }}
  • [ ] Result preview checked on Item 0 and Item 1 with ›
  • [ ] email added by dropping the field onto Drag input fields here
  • [ ] late_fee is type Number, switched to Expression before typing
  • [ ] .round(2) on the fee, so 760 gives 15.2, not 15.200000000000001
  • [ ] Execute step returns 5 items in, 5 out

Quick FAQ

What is an item in n8n? One record, such as one invoice or one form submission, with named fields. Nodes pass lists of items and usually run once per item.

What does $json mean? The current item's data.

How do I test without connecting an app? Open the trigger, click set mock data, paste JSON, save. Test runs use the pinned data.

The full lesson, with a practice copy of the n8n editor that checks each of the 28 steps as you do them, is here: n8n: Items, JSON and Expressions, Explained by Doing.

Top comments (0)