Now inviting automation leaders: publish your playbook as a skill, under your own name. Publish yours →
Automation Skills
All skills/n8n binary and data official/MERGE_FOR_CONTEXT
Reference · n8n binary and data official

MERGE_FOR_CONTEXT

Part of n8n binary and data official. Install the skill and your agent reads this page when it needs the depth.

Merge for keeping binary in context

Common: an item with both json and binary runs through a JSON-only operation (Edit Fields, Code, IF), binary disappears, but you need it downstream.

Fix: split the stream, do JSON work on one side, merge binary back.

The pattern

[Source with binary] ─┬─→ [Edit Fields: transform JSON] ─┐
                      │                                    │
                      │   (binary stripped here)           ├─→ [Merge: byPosition] ─→ [Email with attachment]
                      │                                    │
                      └────────────────────────────────────┘
                          (passes binary through unchanged)

The Source feeds two branches:

Merge produces a single item: JSON from top, binary from bottom.

Configuring Merge

{
    type: 'n8n-nodes-base.merge',
    parameters: {
        mode: 'combineByPosition',    // or 'combineAll', 'append', etc.
        joinMode: 'enrichInput1',     // top branch's JSON wins
    },
}

Key choices:

For "combine JSON output with binary stream," combineByPosition is usually right.

Why it works

Merge combines json and binary from its inputs. The side with binary preserves it, and combined with the side holding the JSON you want, the merged item has both.

Alternative: pass-through in the transforming node

Some nodes preserve binary across the operation:

If pass-through is available, use it. Fewer nodes than the Merge dance.

When merge isn't enough

For complex workflows with many strip points:

Threading binary through many JSON-transforming nodes means every node in the chain has to preserve it correctly, and any one of them silently dropping it forces another Merge. Past a couple of strip points, the storage or sub-workflow route is usually less work than keeping the chain honest.

Verifying after merge

test_workflow and inspect via get_workflow_execution:

If binary is missing, check the Merge mode (some don't combine binary) and that the source actually had binary.

Common mistakes

Stripping binary before noticing

By the time you notice, the original is gone. Test with get_workflow_execution after each node during development.

"Merging" a single-source workflow

If only one branch had binary, there's nothing to merge with. The pattern requires splitting the stream so binary travels on one branch.

Merge mode mismatch

combineAll when you wanted combineByPosition produces N×M items instead of N. Specify deliberately.

Publish your skill

Copy this prompt into Claude Code, Codex or any agent. It walks you through your first skill in about 20 minutes, with you as the author.

Click to copy.