What am I missing regarding the *sort* node?

When using the following simple flow design: JSON array inject > split > sort > join > debug, I get no output. When bypassing the sort, I do get output. What am I missing here?

[
    {
        "id": "80d9e2f5beb720ea",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "96321aca8f69c631",
        "type": "inject",
        "z": "80d9e2f5beb720ea",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[1,4,2,3]",
        "payloadType": "json",
        "x": 100,
        "y": 80,
        "wires": [
            [
                "2a15a5afce1ed0c9"
            ]
        ]
    },
    {
        "id": "e5231bc4ba987cc0",
        "type": "debug",
        "z": "80d9e2f5beb720ea",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 820,
        "y": 80,
        "wires": []
    },
    {
        "id": "2a15a5afce1ed0c9",
        "type": "split",
        "z": "80d9e2f5beb720ea",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "property": "payload",
        "x": 270,
        "y": 80,
        "wires": [
            [
                "42079507a2050bfc",
                "1d1546a7804d5e4e"
            ]
        ]
    },
    {
        "id": "42079507a2050bfc",
        "type": "sort",
        "z": "80d9e2f5beb720ea",
        "name": "",
        "order": "ascending",
        "as_num": true,
        "target": "payload",
        "targetType": "msg",
        "msgKey": "payload",
        "msgKeyType": "elem",
        "seqKey": "payload",
        "seqKeyType": "msg",
        "x": 450,
        "y": 40,
        "wires": [
            [
                "1d1546a7804d5e4e"
            ]
        ]
    },
    {
        "id": "1d1546a7804d5e4e",
        "type": "join",
        "z": "80d9e2f5beb720ea",
        "name": "",
        "mode": "auto",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "useparts": false,
        "accumulate": "false",
        "timeout": "",
        "count": "",
        "reduceRight": false,
        "x": 630,
        "y": 80,
        "wires": [
            [
                "e5231bc4ba987cc0"
            ]
        ]
    }
]

The split, sort, and join are all using default configuration.

In the image above, I've linked the join straight to the split, and then I get a single message in the debug output, where I'm expecting to see 2 messages: one sorted, and the other unsorted.

Current output:

Node-RED version: v4.0.9
Node.js version: v20.17.0

The sort node will sort the array. By splitting the array you are passing numbers to the sort node not an array.

If you want to sort the array delete the split and join nodes.

You will not see two messages as the join uses the msg.parts object to join in automatic mode, as the now split messages share msg.parts they negate each other. set debugs to show complete message object to see msg.parts.

p.s. Hi and welcome to the forum

Thanks, you've pointed me in the right direction by stating that the sort node can sort an array directly. I wanted to use the node to sort my message sequence, and it turns out the documentation does mention that it's possible. I needed to set the Sort property to "message sequence".

p.s. Thank you! Happy to be here!

2 Likes