Accessing nested object in node code (run once each item)

Describe the problem/error/question

I am not able to access the nested object “new_tags” in the node code.

The code below…

const new_tags = $input.item.json.output;

return {
  json: {
    new_tags
  }
};

return…

[
 {
   "new_tags": {
    "new_tags": [
     "Méthode d'organisation"
    ]
   }
  }
]

But this code :

const new_tags = $input.item.json.output.new_tags;

return {
  json: {
    new_tags
  }
};

return…
Cannot read properties of undefined (reading 'new_tags') [line 1, for item 9] [item 9]

If I use the run once for all items, I can access it. But not in the run once for each item.

Information on your n8n setup

  • n8n version: 1.42.1
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): ?
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker (locally)
  • Operating system: MacOS

Thanks for your help,
Damien

I have found the issue : the json object isn’t consistent.
So : $input.item.json.output?.new_tags || []

Thanks :slight_smile:

2 Likes

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