Expression Returning [undefined] Instead of Value

Hi everyone, I’m having an issue with expressions in n8n. I’m trying to access a value from a previous node, but instead of getting the value, I get:
[undefined]
My workflow is:
HTTP Request → Set → HTTP Request
In the second HTTP Request node, I’m trying to use:
{{$json.user.id}}
But the output is [undefined], even though I can see the data exists in the previous node.
Sometimes it works, sometimes it doesn’t, which is confusing.
I’m not sure if:
• The data structure is different than I think
• I should be referencing the previous node directly
• Or I’m accessing the wrong path

Describe the problem/error/question

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

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

Hi @Keira_Becky This usually means the path you’re using doesn’t exist on that item.

Even if you see the data in a previous node, $json only looks at the current item. So if the structure changed, this will return undefined:

{{$json.user.id}}

First, check the actual structure in the execution preview. Maybe it’s:

{{$json.id}}

or:

{{$json.user?.id}}

Safer option You can just Reference the node directly:

{{$node[“Set”].json[“user”][“id”]}}

Hi @Keira_Becky instead of json$.user.id try using {{ $input.first().json.user.id }} or {{ $('Your Node Name').first().json.user.id }} sometimes first().item.json or item.objectName occurs to be mindful with that, and it would work.

@Keira_Becky the intermittent part is the clue — your Set node is probably outputting multiple items and only some have user.id. drop a Code node between Set and the second HTTP Request to filter those out:

the Set node flattens user.id into userId so the second request doesn’t need nested access, and the Code node kills any items where it came back undefined before they hit the next HTTP call. swap the URLs for your real endpoints.