ERROR: Unexpected token '{'

hello team, new user here.

I feel stupid right now, but here’s my question.
based on that doc : Welcome | n8n Docs

I fetch some data from gsheet with success.
I want to manipulate data with “function” node
If I am using “set” node with expression, I have my value like :

{{$node["Google Sheets"].data["data"]["0"][0]}} = 123456

but if I am using “function” like this :

const test = {{$node["Google Sheets"].data["data"]["0"][0]}}
return test

I have an error msg like :

ERROR: Unexpected token '{'
/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes:1
(function (exports, require, module, __filename, __dirname) { module.exports = async function() {const test = {{$node["Google Sheets"].data["data"]["0"][0]}};

I tried a lot of thing and get error msg also like :

ERROR: Always an Array of items has to be returned!

If you have any docs or way to solve this, it’s appreciated,

thank you ,

Welcome to the community!

It seems like you are mixing up two different syntax. One are expressions in parameters. They are always encapsulated in {{ }}
How they work is documented here:

And then there are the Function-Nodes which are pure JavaScript. Their documentation can be found here:

A Function Nodes always expects an array as return value and that has to be an array of items (an item has always a “json” property). The data structure is described here:

So not exactly sure what you want to do but the code you want is probably something like this in case the “Google Sheet” Node is connected directly to the Function-Node:

return [
  {
    json: {
      test: items[0].json.data[0][0]
    }
  }
];

If other nodes are inbetween it is something like this:

return [
  {
    json: {
      test: $node["Google Sheets"].data.["data"][0][0]
    }
  }
];

Hope that helps!

hello, thank you for url,

I am trying to load the previous quote, but receive that error :

have you an idea, why ?

here’s my workflow :

I added a dot (after data) which should not be there. So like this:

return [
  {
    json: {
      test: $node["Google Sheets"].data["data"][0][0]
    }
  }
];