Fix: n8n null and undefined values in workflows

    n8n can pass missing data as null, undefined, empty strings, or the literal text "null". Detect each form in a Code node before the item reaches an API, database, or dispatch action.

    Last updated 2026-09-21~6 min read
    n8nCode nodeJavaScriptIF nodeData validation

    Last updated: 2026-06-08 · Tested on n8n 1.x · ~4 min read

    Symptoms — what you're seeing

    • An n8n expression returns nothing even though the previous node appears to contain the field
    • An API request receives a missing property, an empty string, or the literal text "null"
    • An IF node treats an incomplete item as valid because the condition only checks for a real null value
    • A Code node throws an error when it reads a nested property from an item that does not contain the parent object
    • A database or spreadsheet receives blank rows after an extraction, webhook, or merge step

    Why this happens

    n8n does not have one universal representation for missing data. A field can be absent from the JSON object and evaluate to undefined, explicitly set to null, returned as an empty string, contain only whitespace, or contain the literal text "null" from an extractor or AI node.

    The failure usually comes from one of four design problems:

    1. The condition checks only real null. A condition such as value !== null still accepts undefined, "", and "null". That lets incomplete data continue.

    2. A nested property is read without checking its parent. An expression that expects customer.email fails when customer is absent. Use optional chaining in JavaScript, then validate the result explicitly.

    3. An extraction or AI node returns text instead of a value. Document parsers and structured-output prompts can return the string "null". JavaScript treats that as a non-empty string, so a basic truthiness check does not catch it.

    4. The workflow has no rejection path. Detecting a missing value is not enough. The workflow must stop the affected item before the HTTP Request, database, email, or dispatch node and record why it was rejected.

    The fix, step by step

    1. Inspect the incoming item first. Open the execution data for the node immediately before the failure. Confirm whether the field is absent, null, undefined, empty, whitespace, or the literal string "null". Do not write the condition from the expected schema alone.
    2. Read optional nested fields safely. In a Code node, use optional chaining when a parent object may be missing. For example, const email = item.customer?.email; produces an undefined value that the validation helper can handle instead of throwing before the check runs.
    3. Centralize the missing-value check. Use one helper for real null, undefined, empty strings, whitespace, and the literal string "null". Do not duplicate slightly different checks across ten fields.
    4. Validate required fields in a Code node. The Code node should return a clear decision and identify every missing field. Replace the example field names below with the fields your downstream API or database actually requires.
      const requiredFields = [
        "customerEmail",
        "invoiceNumber",
        "amount"
      ];
      
      const isMissing = (value) => (
        value === null ||
        value === undefined ||
        (typeof value === "string" && (
          value.trim() === "" ||
          value.trim().toLowerCase() === "null"
        ))
      );
      
      return $input.all().map(({ json: item }) => {
        const missingFields = requiredFields.filter((field) =>
          isMissing(item[field])
        );
      
        return {
          json: {
            ...item,
            validation: {
              decision: missingFields.length === 0 ? "APPROVED" : "REJECTED",
              reason: missingFields.length === 0 ? null : "missing_required_fields",
              missingFields,
              checkedAt: new Date().toISOString()
            }
          }
        };
      });
    5. Handle nested values before validation. Map nested data into named fields before checking it. For example, assign customerEmail from item.customer?.email and validate customerEmail. This makes the validation result readable and prevents a downstream node from using a different path than the one you checked.
    6. Route rejected items with an IF node. Check whether validation.decision equals APPROVED. Only that branch may continue to the HTTP Request, database insert, email, or dispatch action. Send the rejected branch to logging, a notification, or manual review.
    7. Do not silently replace missing data. A default such as value || 0 can convert a missing amount into a valid-looking number. Use defaults only when zero or another fallback has a defined business meaning. Otherwise, reject the item.

    Stuck on this for more than 30 minutes? Book a 30-min call. I'll get on Zoom, look at your workflow, and either fix it on the call or scope what it'll take. No upsell, no decks.

    Common variations

    • The field is missing after a Merge node. Check which input supplies the field and whether the Merge mode produces one item or multiple items. Inspect the merged JSON rather than assuming both inputs have the same shape. If the merge also creates duplicate or bypassed items, compare the workflow against the n8n production reliability checklist.
    • An expression displays blank data. Confirm the node and item reference in the expression. A correct field path from one node can evaluate to undefined when copied to a different node or item context.
    • The parser returns the string "null". Treat it as missing after trimming and lowercasing. Do not rely on JavaScript truthiness because a non-empty string is truthy.
    • Zero is being rejected as missing. Do not use !value for numeric fields when zero is valid. Check null, undefined, and empty strings explicitly so a legitimate zero survives.
    • The workflow continues after validation fails. Check every path leaving the validation node. A retry branch, pinned test data, separate trigger, or AI tool call can bypass the IF node and send the incomplete item anyway. If the downstream action is OpenAI, separate missing-value handling from the retry and n8n OpenAI 429 rate-limit diagnosis.

    When this isn't the issue

    If the field exists in the execution data but the downstream node still receives the wrong value, the problem is a path, item-mapping, or data-type issue rather than null handling.

    • Confirm the expression references the correct node and item index
    • Check whether a Set or Edit Fields node renamed the property before the failing node
    • Inspect whether a Merge node produced multiple items and the next node is reading only the first one
    • Check whether the downstream API expects a number, boolean, array, or object instead of a string

    Related fixes

    Book a 30-min scope call → Email Basit

    Need this workflow customized or debugged? Book a 30-min scope call →

    Stuck configuring this workflow?

    I build and fix n8n workflows for agencies and SaaS teams. 30-minute scope call — bring the problem, leave with an estimate.