Fix “Cannot read properties of undefined” in n8n
What this error means
Your expression walks into an object one level at a time. If any level along the path is missing for the current item, JavaScript has nothing to read the next property from and stops with this error. The word in brackets is the property it tried to read.
Common causes
- The field is missing for some items only (one customer has no shipping address, one webhook omits a block).
- A typo in a field name, so the parent level is
undefinedfor every item. - The data is nested differently than you expect, e.g. under
bodyfor Webhook nodes ($json.body.order, not$json.order). - You are reading from the wrong item or node, so the object you expect isn't there.
How to fix it
- Open the failing node, look at its input panel and find the exact path to the value — including
bodyfor webhooks. - Replace each risky dot with
?.so a missing level returnsundefinedinstead of throwing. - Add a fallback with
??so the next node always receives a usable value. - If the missing data means the item should not continue, add an IF or Filter node before the step instead of a fallback.
❌ Breaks
{{ $json.order.shipping.country }}✅ Works
{{ $json.order?.shipping?.country ?? 'Unknown' }}💡 Pro tip: Optional chaining hides missing data silently. If a missing field means bad data, it's often better to stop the item with an IF node and alert someone than to write 'Unknown' into your CRM.
🧪 Fix it yourself
Some orders arrive without a shipping block, and the workflow crashes on them. Make the expression return the country, or 'Unknown' when shipping is missing.
// Item 1
{ "order": { "id": 1, "shipping": { "country": "AE" } } }
// Item 2
{ "order": { "id": 2 } }
⚙️ Your fix is executed against both test items — any correct solution passes.
✅ Solution
Output: "AE" and "Unknown"