Return items pattern in n8n
Why incorrect return patterns in Code nodes cause silent data loss
What is this issue?
n8n Code nodes expect items to be returned in a specific format: an array of objects with 'json' (and optionally 'binary') properties. Returning data in the wrong format causes errors or silent data loss.
Common mistakes:
•Returning raw objects instead of {json: ...} wrappers•Returning a single item instead of an array•Forgetting to return anything (implicit undefined)•Mixing item formats inconsistently
Why is this a problem?
Silent data loss
Invalid return formats may result in empty output without error.
Type errors
Downstream nodes fail when receiving malformed items.
Inconsistent behavior
Sometimes it works, sometimes it doesn't, depending on the data.
Debugging difficulty
The error message doesn't clearly indicate the return format issue.
How to fix it
- 1
Use correct format
Always return: return items.map(item => ({ json: { ...your data } }))
- 2
Check Run Once Each Item
In 'Run Once for Each Item' mode, return a single {json: ...} object.
- 3
Use $input helpers
Use $input.all() and modify items rather than creating from scratch.
- 4
Validate output
Add console.log(items) before return to verify the format.
Scan your workflow now
Upload your n8n workflow JSON and detect Code nodes with potentially incorrect return patterns.