APIs return incomplete data constantly -- optional fields come back as `null`, empty strings, or are missing entirely.
APIs return incomplete data constantly -- optional fields come back as null, empty strings, or are missing entirely. Without fallbacks, a single null value can crash downstream nodes that expect a string. Defensive expressions cost almost nothing and prevent entire workflow failures.
Real-world example: A contact form webhook sometimes omits the company field. A downstream Slack message node uses that field in its text. Without a fallback, the message shows "undefined."
// Basic fallback with ||
{{ $json.company || "No company provided" }}
// Nullish coalescing for when 0 or "" are valid values
// (|| treats 0 and "" as falsy; ?? only catches null/undefined)
{{ $json.score ?? 0 }}
// Nested fallback chain
{{ $json.preferred_name || $json.first_name || "Valued Customer" }}
// Conditional with ternary
{{ $json.is_premium ? "Premium Support" : "Standard Support" }}
// Safe property access for deeply nested objects
{{ $json.metadata?.custom_fields?.priority || "normal" }}
```text
Apply this pattern in an Edit Fields node for data cleaning before any critical downstream step:
| Output Field | Expression |
|----------------|-------------------------------------------------------------|
| `contactName` | `{{ $json.name \|\| "Unknown Contact" }}` |
| `company` | `{{ $json.company \|\| "Unaffiliated" }}` |
| `priority` | `{{ $json.metadata?.priority \|\| "normal" }}` |
| `score` | `{{ $json.lead_score ?? 0 }}` |
> **Tip: Validate Early**
>
> Place a fallback/cleaning Edit Fields node immediately after your data source (webhook, API call, database query). This single "sanitizer" node protects every downstream node from null-related failures.
Adding fallbacks at the data entry point of your workflow prevents cascading errors and makes debugging significantly easier.
**Related:** [Flatten Deeply Nested API Responses](../code-node-mastery/01-flatten-deeply-nested-api-responses.md) | [Use the HTTP Request Node as a Universal Connector](../integration-patterns/01-use-the-http-request-node-as-a-universal-connector.md)
I build production n8n and Cloudflare automation for teams — the same engineering behind HarperFlow. Fixed-price, escrow-protected, US-based.