Handle arrays of json

{{$node["XML"].data["serv:message"]["serv:body"]["serv:bodyContent"]["use:user"]}}

I have the following expression that gives me an array of objects. I’m trying to do…

for each in user:
append(user.userID)

So iterate over the array of objects and append to a google sheet. SetNode seems to not iterate. Function has to return an array. Should I use Function Item in this case, and how?

@levensailor The Google sheet will automatically iterate over all elements. Check the example below.

{
  "nodes": [
{
  "parameters": {},
  "name": "Start",
  "type": "n8n-nodes-base.start",
  "typeVersion": 1,
  "position": [
    250,
    300
  ]
},
{
  "parameters": {
    "functionCode": "return [{\n    json: {\n        data: [ {\n                id: 1,\n                name: 'ricardo'\n                }\n        ],\n\n    },\n},\n{ json: {\n    data: [\n    {\n        id: 1,\n    name: 'rodolfo'\n    }\n    ]\n }\n }\n]"
  },
  "name": "Function",
  "type": "n8n-nodes-base.function",
  "typeVersion": 1,
  "position": [
    480,
    300
  ]
},
{
  "parameters": {
    "operation": "append",
    "sheetId": "14ZJZBWmOWOFr9NldppEHnACOTReECG3olxG7VgLInHI",
    "options": {}
  },
  "name": "Google Sheets",
  "type": "n8n-nodes-base.googleSheets",
  "typeVersion": 1,
  "position": [
    890,
    300
  ],
  "credentials": {
    "googleApi": "asasas"
  }
},
{
  "parameters": {
    "keepOnlySet": true,
    "values": {
      "number": [
        {
          "name": "id",
          "value": "={{$node[\"Function\"].json[\"data\"][0][\"id\"]}}"
        }
      ],
      "string": [
        {
          "name": "name",
          "value": "={{$node[\"Function\"].json[\"data\"][0][\"name\"]}}"
        }
      ]
    }
  },
  "name": "Set",
  "type": "n8n-nodes-base.set",
  "typeVersion": 1,
  "position": [
    670,
    300
  ]
}
  ],
  "connections": {
"Start": {
  "main": [
    [
      {
        "node": "Function",
        "type": "main",
        "index": 0
      }
    ]
  ]
},
"Function": {
  "main": [
    [
      {
        "node": "Set",
        "type": "main",
        "index": 0
      }
    ]
  ]
},
"Set": {
  "main": [
    [
      {
        "node": "Google Sheets",
        "type": "main",
        "index": 0
      }
    ]
  ]
}
  }
}
1 Like