Map HTTP node response to n8n data structure

Hi

I would i would like to make make a workflow that contains a json with multiple items.

How do I make this to repeat the nodes that come after for one per item and repeats for all items in the json.

The one in red is the node that contains the items I want to repeat

I have copied an example of the data here

  "nodes": [
    {
      "parameters": {
        "functionCode": "const item= [\n{\n  json: \n    [\n  {\n    \"id\": \"9e0d11bc-842e-4afb-904d-9df2a2c96b0e\",\n    \"name\": \"tese\",\n    \"locationId\": \"0b286d82-70b1-4e48-b7ce-544c3b922c38\",\n    \"metadata\": {}\n  },\n  {\n    \"id\": \"1186879e-2d0d-4e4e-94d7-621b1443f67e\",\n    \"name\": \"test2\",\n    \"locationId\": \"0b286d82-70b1-4e48-b7ce-544c3b922c38\",\n    \"metadata\": {}\n  },\n  {\n    \"id\": \"f864f33c-3962-42b7-96dd-924e8309b4e5\",\n    \"name\": \"test2\",\n    \"locationId\": \"0b286d82-70b1-4e48-b7ce-544c3b922c38\",\n    \"metadata\": {}\n  },\n  {\n    \"id\": \"f03d835b-2e51-4e25-829d-15aa7028e09f\",\n    \"name\": \"Test checklist\",\n    \"locationId\": \"0b286d82-70b1-4e48-b7ce-544c3b922c38\",\n    \"metadata\": {\n      \"OS\": \"IOS\",\n      \"Device\": \"PC\",\n      \"Date\": \"2020-08-12\"\n    }\n  },\n  {\n    \"id\": \"78b7f35e-94e8-4f33-b9b0-589e19f45d5e\",\n    \"name\": \"AL - Notification of loss\",\n    \"locationId\": \"0b286d82-70b1-4e48-b7ce-544c3b922c38\",\n    \"metadata\": {}\n  },\n  {\n    \"id\": \"53aefb60-3285-4430-9bfe-bd4205a92889\",\n    \"name\": \"Connector 1\",\n    \"locationId\": \"0b286d82-70b1-4e48-b7ce-544c3b922c38\",\n    \"metadata\": {}\n  }\n]   \n}\n\n];\n\nreturn item;\n"
      },
      "name": "items",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1270,
        290
      ]
    }
  ],
  "connections": {}
}

how does the node in red returns the data exactly? @Mattias_Larsson

HI

Like this

@Mattias_Larsson Check the example below. The mockup function node is mocking the “checkForActiveFlow” HTTP node and the map to n8n data structure function node is what you have to put after the checkForActiveFlow node.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const items = [{ json: [{ id: 123 }, { id:456 }]  }]\n\nreturn items;\n\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        510,
        300
      ],
      "notesInFlow": true,
      "notes": "Mockup"
    },
    {
      "parameters": {
        "functionCode": "const result = [];\n\nconst data = items[0].json\n\nfor (const d of data) {\n    result.push({ json: d })\n}\n\nreturn result"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        770,
        300
      ],
      "notesInFlow": true,
      "notes": "Map to n8n data structure"
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thanks just tried it quickly and it seems to work

Will try it more tommrow

Highly appreciated