How to use fromAI command in inside code tool ( or output value from previous tool)

:question: 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:

  1. How do I access the output of the previous node (like the AI Tool) inside the Code node?
  2. Is there any equivalent of {{$fromAI('json')}} that works inside the Code node?
  3. 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 :pray:

Information on your n8n setup

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

In the Code node, you don’t use {{$fromAI('json')}} — that syntax is for expression editor, not JavaScript.

Instead, inside the Code node you access data using: const inputData = $input.item.json;

if you’re looping through multiple items: const items = $input.all();

An arbitrary example:

to access your data i think it would be something like

let temp = JSON.parse(query)
let endTime = temp[0]['end']

the conversion is up to you

i am using the AI agnet nodes .i am using AI agent what ever i got the input OUPUT FROM outlook get event . i need to pass in a code module. i already tried you way . it is not working.

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