Repat function node based on array of json

Hi I am still struggling a bit when it comes to repeating item

I have a json which has an array of data, I want to add this data one for each item in the array after the last function node to a Postgres database I do only manage to get to add the first one

There are multiple ways to write that. One in simple code would be this:

Thanks works great. Still learning;)

Great to hear! Have fun!

Hi,

how i can have the 3 entries as an output like in each row (table)


Array to …

Thanks,
Stefan

ForEach ? Would be the right function ?

Hey @Stefan, not sure if I understand well what you want to do. I’m guessing this is the response from an HTTP request and you want to get jus the patients. If so, check the example below.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://mockup-pj5l0yxsjrbr.runkit.sh/",
        "options": {}
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        540,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const results = []\n\nfor (const item of items) {\n  for (const patien of item.json.Response.patiens) {\n    results.push({\n        json: {\n            patien, \n        }\n     })\n  }\n}\n\nreturn results\n\n\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        750,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

you are great !! Thanks again