How to Use Output from Previous Node (like an AI Tool) Inside the Code Node in n8n (Self-hosted Docker)
Hi everyone,
I’m using the latest version of n8n (self-hosted via Docker). I have an AI Agent node that outputs data in UTC timezone, and I want to convert this datetime data to IST inside a Code node.
The AI tool outputs data like this:
{
"query": "[{\"start\":{\"dateTime\":\"2025-04-17T04:30:00Z\"},\"end\":{\"dateTime\":\"2025-04-17T05:30:00Z\"}}]"
}
I want to access this query
value inside the Code node, parse it, convert the UTC times to IST, and output the modified result.
My Questions:
- How do I access the output of the previous node (like the AI Tool) inside the Code node?
- Is there any equivalent of
{{$fromAI('json')}}
that works inside the Code node? - What’s the correct way to reference incoming JSON values like
query
from the previous node?
I tried using this:
const raw = {{$fromAI('json')}};
But it gives a syntax error: Unexpected token '{'
.
Any help or best practices for using the Code node with input data from AI tools or other nodes would be appreciated!
Thanks
Information on your n8n setup
- n8n version:
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker):
- Operating system: