The n8n Code node error “json property isn’t an object” almost always means your return value does not match n8n’s item format. Here is the model and a reliable fix.
n8n items are not raw arrays of objects—each item needs a json property.
How n8n represents items
Downstream nodes expect an array of items, each shaped like:
{ json: { /* your fields */ }, binary?: { /* optional */ } }
If you return [{ name: "Ada" }] you skipped the json wrapper.
Wrong vs right
Wrong (flat object list):
return [{ id: 1 }, { id: 2 }];
Right:
return [
{ json: { id: 1 } },
{ json: { id: 2 } },
];
Mapping API arrays safely
const rawArray = $input.all();
const formattedOutput = rawArray.map((item) => {
if (item.json && typeof item.json === 'object' && !Array.isArray(item.json)) {
return item;
}
const payload = item.json !== undefined ? item.json : item;
return {
json: {
...(typeof payload === 'object' && payload ? payload : { value: payload }),
processed_at: new Date().toISOString(),
},
};
});
return formattedOutput;
Prefer “Run Once for All Items” when reshaping entire payloads at once.
Run mode matters
- All items: one JS run sees
$input.all()— best for reshape/merge. - Each item: runs per item with
$json— best for simple field maps.