Hello everybody! When is connection.index greater than 0?

export interface IConnection {
    node: string;
    type: string;
    index: number;
}

Hey, a connection in n8n would be the link between one node and the next. The IF node for example would have two connections, the Switch node has four.

hello @MutedJam , I don’t think I’m very clear,

{
    "Device Info1": {
        "main": [
            []
        ]
    },
    "Start": {
        "main": [
            [
                {
                    "node": "IF",
                    "type": "main",
                    "index": 0
                }
            ]
        ]
    },
    "IF": {
        "main": [
            // main[index] is what you just said. I see
            [
                {
                    "node": "Device Info",
                    "type": "main",
                    "index": 0   // When is the index greater than 0?
                }
            ],
            [
                {
                    "node": "Device Info1",
                    "type": "main",
                    "index": 0
                }
            ]
        ]
    }
}

Oh, interesting, I never paid attention to the actual index value inside the workflow JSON and have no clue why it would be there for both connection. Let’s see if someone else can shine some additional light on this :slight_smile:

1 Like

Not sure if it’s helpful but I found something in my WFs

The merge node has index: 1 so I assume that maybe it will happened if >1 input or sth similar

2 Likes

Exactly, the index says to which input the node is connected to. As the index starts with 0 and most nodes have only one input will you normally always just see index 0 and 1 only if a Merge-Node is involved if it has something connected to the second input (index 1).

2 Likes

I see. thank you all @MutedJam @Shirobachi @jan