Issues with "items" json key colission

Describe the problem/error/question

By backend has a ‘list’ GET endpoint that replies with paginated response looking like this:

{
  "items": [...],
  "total": 0,
  ...
}

And when I try to access elements of “items” list from “Code” (Python) node, I see this error below. I tried to access it via getattr, error is the same.

JavaScript Code node does NOT have this problem.

What is the error message (if any)?

TypeError: ‘builtin_function_or_method’ object is not iterable

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.102.3
  • Database (default: SQLite): does not matter
  • n8n EXECUTIONS_PROCESS setting (default: own, main): does not matter
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker (I believe it does not matter)
  • Operating system: docker official image

PS I think it’s pretty obvious that this behavior is caused by a name collision with the built-in “items”, and I fixed it in my case with an additional Set layer, in which I renamed the name of this key

This would do too

res = {"res": 0}
for input in _input.all():
  items = input.json.to_py()['items']
  res["res"] += sum(items)
return res

And this:

res = {"res": 0}
for item in _input.all():
  items = item.json["items"]
  res["res"] += sum(items)
return res

Here are both:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.