ERROR: Unexpected token '{'

hello team, new user here.

I feel stupid right now, but here’s my question.
based on that doc : https://docs.n8n.io/#/nodes?id=function-node

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:
https://docs.n8n.io/#/node-basics?id=expressions

And then there are the Function-Nodes which are pure JavaScript. Their documentation can be found here:
https://docs.n8n.io/#/nodes?id=function-node

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:
https://docs.n8n.io/#/data-structure

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 :

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        180,
        190
      ]
    },
    {
      "parameters": {
        "sheetId": "1lYd-5vWRTwNFL0TS8oqbV3DPKbQgF5Bdaf-gFu8Q380",
        "range": "liste des services!M2:M10",
        "rawData": true,
        "options": {}
      },
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        440,
        260
      ],
      "credentials": {
        "googleApi": "googleapi"
      }
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      test: $node[\"Google Sheets\"].data.[\"data\"][0][0]\n    }\n  }\n];\n\n\n\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        700,
        220
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

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

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