r/u_Boring-Shop-9424

▲ 8 r/u_Boring-Shop-9424+7 crossposts

$json vs $items() in n8n — the difference that actually matters

If you're new to n8n and mixing these up, here's the short version:

$json is the current item's data in the current context. Use it inside a Code node set to "Run Once for Each Item", or inline in expressions like {{ $json.email }}.

$items() is the old-school way to grab an array of items from a specific node. It still works in a lot of workflows you'll find online, but it's legacy syntax. The modern equivalent is $input.all() inside a Code node, or $('Node Name').all() in expressions — both are more explicit about which node's data you're pulling.

Rule of thumb I use: if I'm working with ONE item, $json. If I need ALL items to loop, aggregate, or compare, $input.all(). I basically never reach for $items() anymore, but it's worth recognizing when you see it in older templates.

Curious if anyone still has a real use case for $items() over $input.all() — haven't run into one myself.

reddit.com
u/Boring-Shop-9424 — 3 days ago
▲ 9 r/u_Boring-Shop-9424+6 crossposts

Small habit that saved me from so many undefined errors in n8n Code nodes

Quick tip for anyone writing Code nodes in n8n: stop accessing nested fields directly.

$json.field.subfield will throw the second `field` doesn't exist on some items in your batch — and with n8n that happens more often than you'd think (APIs returning partial data, webhooks with optional fields, etc).

Just use optional chaining everywhere:

$json.field?.subfield

And if you need a fallback value, stack the nullish coalescing on top:

$json.field?.subfield ?? 'default'

Saved me from a bunch of random workflow failures that only showed up on specific items, not the whole batch — which made them annoying to debug in the first place.

Anyone else have small JS habits like this that cleaned up their Code node errors?

reddit.com
u/Boring-Shop-9424 — 5 days ago