Skip to content
1 min read 260 words

n8n Code Node: Fix "json property isn't an object"

Understand n8n item structure, fix Code node JSON wrapping errors, and map arrays correctly in JavaScript and Python.

WorkFlowAI editorial · Trust

#n8n #javascript #code-node #troubleshooting

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.

JavaScript code for debugging n8n Code node JSON structure

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;

Developer writing automation scripts for n8n pipelines

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.

About the publisher

WorkFlowAI is an open catalog of AI automation workflows, MCP servers, and tools. Guides are written to help operators install and evaluate recipes — with honest Verified vs Community labels.

Related reading

Use this in the library

← All posts