Split Array and Objects

Hy,
i have a HTTP request that gives me several arrays with objects.
payload.List.Item[0], payload.List.Item[1], payload.List.Item[2].....

How to split those objects from all arrays into single requests?

I need from each array the payload.List.Item[0].Active

Thank you!

Welcome to the forum!

This guide will help you get an understanding of the path to objects in an array.

https://nodered.org/docs/user-guide/messages

thanks for your answer =)
I know the site.
if I want to "filter" a single array, then I know how to do it.
I just don't understand how to use this when I have multiple objects
[0 … 9]
[10 … 19]
[20 … 29]
.....

I just want to filter for all "active".

payload.List.Item[0].Active[0] == 1
payload.List.Item[2].Active[0] == 1
payload.List.Item[8].Active[0] == 1

I can't create a switch node for each individual object?!

In a change node set msg.payload
to JSONata J: $$.payload.List.Item[Active[0] = "1"]

Which should return payload, with an array of objects where active[0] = "1"
Which you can feed in to a split node to get separate payload objects.

1 Like

Amazing!!!! Thank you!

now only the "active ones" are shown to me!
after that I would now set a "split-node" so that they are listed individually.

if I want to evaluate the payload so that ONLY the host name is displayed to me.... do you have an idea for this?
payload.HostName[0]
so that I have them all in a "list" again? (Or does this belong in a separate thread?)

Your question is ambiguous, I will take a guess, but if wrong please supply more info

$$.payload.List.Item[Active[0] = "1"].Hostname[0] should return alist of hostnames before the split.

After the split msg.payload.HostName[0] would hold the individual hostnames of each split message.

ambiguous :woozy_face: sorry...

$$.payload.List.Item[Active[0] = "1"].Hostname[0]
If I then filter (i.e. I replace this with the one from your previous message) then the result I get is: undefined

I'll try to explain it to you even better.... but what do you need to know?

Always best to supply input data, in a copyable form, and example test flow with input data in an inject node, as we do not have your data. any error messages. Then we can see what you are trying and offer an example flow back. We only require 3 elements of your input array, not the whole thing.

if you can start something like that with it, that would be great... but it's probably a config that not everyone uses...

[
    {
        "id": "af13048d4c5fc875",
        "type": "inject",
        "z": "9e0ebf9d.29a6c",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 1580,
        "y": 4440,
        "wires": [
            [
                "fb035b3a04461cab"
            ]
        ]
    },
    {
        "id": "fb035b3a04461cab",
        "type": "fritzbox-in",
        "z": "9e0ebf9d.29a6c",
        "device": "61f053c7.62e594",
        "name": "",
        "service": "urn:dslforum-org:service:Hosts:1",
        "action": "X_AVM-DE_GetHostListPath",
        "arguments": "{}",
        "x": 1750,
        "y": 4440,
        "wires": [
            [
                "ed8e4aceedc1825f"
            ]
        ]
    },
    {
        "id": "ed8e4aceedc1825f",
        "type": "change",
        "z": "9e0ebf9d.29a6c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "url",
                "pt": "msg",
                "to": "\"http://192.168.178.1:49000\" & payload.\"NewX_AVM-DE_HostListPath\"",
                "tot": "jsonata"
            },
            {
                "t": "delete",
                "p": "payload",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1930,
        "y": 4440,
        "wires": [
            [
                "7b5e7201d2d5feb5"
            ]
        ]
    },
    {
        "id": "7b5e7201d2d5feb5",
        "type": "http request",
        "z": "9e0ebf9d.29a6c",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 2110,
        "y": 4440,
        "wires": [
            [
                "86013a34ab79cd68"
            ]
        ]
    },
    {
        "id": "86013a34ab79cd68",
        "type": "xml",
        "z": "9e0ebf9d.29a6c",
        "name": "",
        "property": "payload",
        "attr": "",
        "chr": "",
        "x": 2250,
        "y": 4440,
        "wires": [
            [
                "bd36ce309c7bac12",
                "910fd97075f98887",
                "a5ea3096d0529acc"
            ]
        ]
    },
    {
        "id": "bd36ce309c7bac12",
        "type": "debug",
        "z": "9e0ebf9d.29a6c",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 2410,
        "y": 4440,
        "wires": []
    },
    {
        "id": "4ae45f9a0bc91f0f",
        "type": "split",
        "z": "9e0ebf9d.29a6c",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": true,
        "addname": "payload.hits",
        "x": 2430,
        "y": 4620,
        "wires": [
            [
                "e2f2fdf991dcc1a5"
            ]
        ]
    },
    {
        "id": "a8e5c88ab1ab8ef6",
        "type": "debug",
        "z": "9e0ebf9d.29a6c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 2470,
        "y": 4540,
        "wires": []
    },
    {
        "id": "910fd97075f98887",
        "type": "change",
        "z": "9e0ebf9d.29a6c",
        "name": "$$.payload.List.Item[Active[0] = \"1\"]",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$$.payload.List.Item[Active[0] = \"1\"]",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2210,
        "y": 4540,
        "wires": [
            [
                "a8e5c88ab1ab8ef6",
                "4ae45f9a0bc91f0f"
            ]
        ]
    },
    {
        "id": "a5ea3096d0529acc",
        "type": "change",
        "z": "9e0ebf9d.29a6c",
        "name": "$$.payload.List.Item[Active[0] = \"1\"].Hostname[0]",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$$.payload.List.Item[Active[0] = \"1\"].Hostname[0]",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2190,
        "y": 4660,
        "wires": [
            [
                "c171c7ca5b4813d0"
            ]
        ]
    },
    {
        "id": "c171c7ca5b4813d0",
        "type": "debug",
        "z": "9e0ebf9d.29a6c",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 2510,
        "y": 4660,
        "wires": []
    },
    {
        "id": "e2f2fdf991dcc1a5",
        "type": "debug",
        "z": "9e0ebf9d.29a6c",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 2590,
        "y": 4620,
        "wires": []
    },
    {
        "id": "61f053c7.62e594",
        "type": "fritzbox-config",
        "name": "FritzBox",
        "host": "fritz.box",
        "port": "49443",
        "ssl": true,
        "user": "USERNAME"
    }
]

I await data in a copyable form

what exactly do you need? isn't the flow not ok for you?

Does the flow contain the incoming payload from the http request?
Are the images showing data copyable?
The debug offers a copy value button, hover to right of object name. Then edit the copied array to 3 array elements using a text editor.

aiaiai... no the pictures can of course be copied...
but how am I supposed to send you the data that the https request outputs, because to be honest I don't...
I could of course give you the debug from the http request. but that would be a miserably long string.

> {"Index":["1"],"IPAddress":["192.168.178.168"],"MACAddress":["14:0A:C5:A0:F9:82"],"Active":["1"],"HostName":["192-168-178-168"],"InterfaceType":["802.11"],"X_AVM-DE_Port":["0"],"X_AVM-DE_Speed":["433"],"X_AVM-DE_UpdateAvailable":["0"],"X_AVM-DE_UpdateSuccessful":["unknown"],"X_AVM-DE_InfoURL":[""],"X_AVM-DE_Model":[""],"X_AVM-DE_URL":[""],"X_AVM-DE_Guest":["0"],"X_AVM-DE_VPN":["0"],"X_AVM-DE_WANAccess":["granted"],"X_AVM-DE_Disallow":["0"]}
this would be for just one... I can't show you all of them because that would be over 80,000 characters.
alternatively maybe only from the active ones? (the debug from your first change node)

Yes! Just that is what @E1cid was asking for.

This is how you present an example flow, notice the data is in the inject node. No need to send us node we do not have installed and if we did would not retrieve your data. See how i edited the array to 5-6 objects.

The flow has several examples, The issue you had was you Typo's vars are case sensitive.

[{"id":"af13048d4c5fc875","type":"inject","z":"20bb0f7f9fab47a8","name":"","props":[{"p":"payload.List.Item","v":"[{\"Index\":[\"1\"],\"IPAddress\":[\"192.168.178.168\"],\"MACAddress\":[\"14:0A:C5:A0:F9:82\"],\"Active\":[\"1\"],\"HostName\":[\"192-168-178-168\"],\"InterfaceType\":[\"802.11\"],\"X_AVM-DE_Port\":[\"0\"],\"X_AVM-DE_Speed\":[\"433\"],\"X_AVM-DE_UpdateAvailable\":[\"0\"],\"X_AVM-DE_UpdateSuccessful\":[\"unknown\"],\"X_AVM-DE_InfoURL\":[\"\"],\"X_AVM-DE_Model\":[\"\"],\"X_AVM-DE_URL\":[\"\"],\"X_AVM-DE_Guest\":[\"0\"],\"X_AVM-DE_VPN\":[\"0\"],\"X_AVM-DE_WANAccess\":[\"granted\"],\"X_AVM-DE_Disallow\":[\"0\"]},{\"Index\":[\"2\"],\"IPAddress\":[\"192.168.178.48\"],\"MACAddress\":[\"F8:4F:AD:96:73:DD\"],\"Active\":[\"1\"],\"HostName\":[\"Android\"],\"InterfaceType\":[\"802.11\"],\"X_AVM-DE_Port\":[\"0\"],\"X_AVM-DE_Speed\":[\"144\"],\"X_AVM-DE_UpdateAvailable\":[\"0\"],\"X_AVM-DE_UpdateSuccessful\":[\"unknown\"],\"X_AVM-DE_InfoURL\":[\"\"],\"X_AVM-DE_Model\":[\"\"],\"X_AVM-DE_URL\":[\"\"],\"X_AVM-DE_Guest\":[\"0\"],\"X_AVM-DE_VPN\":[\"0\"],\"X_AVM-DE_WANAccess\":[\"granted\"],\"X_AVM-DE_Disallow\":[\"0\"]},{\"Index\":[\"6\"],\"IPAddress\":[\"192.168.178.34\"],\"MACAddress\":[\"A8:A7:95:47:13:1A\"],\"Active\":[\"1\"],\"HostName\":[\"BRWA8A79547131A\"],\"InterfaceType\":[\"802.11\"],\"X_AVM-DE_Port\":[\"0\"],\"X_AVM-DE_Speed\":[\"72\"],\"X_AVM-DE_UpdateAvailable\":[\"0\"],\"X_AVM-DE_UpdateSuccessful\":[\"unknown\"],\"X_AVM-DE_InfoURL\":[\"\"],\"X_AVM-DE_Model\":[\"\"],\"X_AVM-DE_URL\":[\"http://192.168.178.34\"],\"X_AVM-DE_Guest\":[\"0\"],\"X_AVM-DE_VPN\":[\"0\"],\"X_AVM-DE_WANAccess\":[\"granted\"],\"X_AVM-DE_Disallow\":[\"0\"]},{\"Index\":[\"7\"],\"IPAddress\":[\"192.168.178.56\"],\"MACAddress\":[\"FC:01:7C:AB:85:BC\"],\"Active\":[\"1\"],\"HostName\":[\"BRWFC017CAB85BC\"],\"InterfaceType\":[\"802.11\"],\"X_AVM-DE_Port\":[\"0\"],\"X_AVM-DE_Speed\":[\"43\"],\"X_AVM-DE_UpdateAvailable\":[\"0\"],\"X_AVM-DE_UpdateSuccessful\":[\"unknown\"],\"X_AVM-DE_InfoURL\":[\"\"],\"X_AVM-DE_Model\":[\"\"],\"X_AVM-DE_URL\":[\"http://192.168.178.56\"],\"X_AVM-DE_Guest\":[\"0\"],\"X_AVM-DE_VPN\":[\"0\"],\"X_AVM-DE_WANAccess\":[\"granted\"],\"X_AVM-DE_Disallow\":[\"0\"]},{\"Index\":[\"14\"],\"IPAddress\":[\"192.168.178.194\"],\"MACAddress\":[\"C4:DD:57:33:6D:D4\"],\"Active\":[\"1\"],\"HostName\":[\"ESP-336DD4\"],\"InterfaceType\":[\"802.11\"],\"X_AVM-DE_Port\":[\"0\"],\"X_AVM-DE_Speed\":[\"72\"],\"X_AVM-DE_UpdateAvailable\":[\"0\"],\"X_AVM-DE_UpdateSuccessful\":[\"unknown\"],\"X_AVM-DE_InfoURL\":[\"\"],\"X_AVM-DE_Model\":[\"\"],\"X_AVM-DE_URL\":[\"\"],\"X_AVM-DE_Guest\":[\"0\"],\"X_AVM-DE_VPN\":[\"0\"],\"X_AVM-DE_WANAccess\":[\"granted\"],\"X_AVM-DE_Disallow\":[\"0\"]}]","vt":"json"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":530,"y":1400,"wires":[["910fd97075f98887","a5ea3096d0529acc"]]},{"id":"910fd97075f98887","type":"change","z":"20bb0f7f9fab47a8","name":"$$.payload.List.Item[Active[0] = \"1\"]","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.List.Item[Active[0] = \"1\"]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":1400,"wires":[["a8e5c88ab1ab8ef6","4ae45f9a0bc91f0f"]]},{"id":"a5ea3096d0529acc","type":"change","z":"20bb0f7f9fab47a8","name":"$$.payload.List.Item[Active[0] = \"1\"].Hostname[0]","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.List.Item[Active[0] = \"1\"].HostName[0]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":1480,"wires":[["7bc99907.bb483","4dd16f57.771cc"]]},{"id":"a8e5c88ab1ab8ef6","type":"debug","z":"20bb0f7f9fab47a8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1250,"y":1300,"wires":[]},{"id":"4ae45f9a0bc91f0f","type":"split","z":"20bb0f7f9fab47a8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":true,"addname":"payload.hits","x":1210,"y":1400,"wires":[["17e291e5.cbab66"]]},{"id":"7bc99907.bb483","type":"split","z":"20bb0f7f9fab47a8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":true,"addname":"payload.hits","x":1270,"y":1480,"wires":[["c171c7ca5b4813d0"]]},{"id":"4dd16f57.771cc","type":"debug","z":"20bb0f7f9fab47a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1190,"y":1540,"wires":[]},{"id":"17e291e5.cbab66","type":"change","z":"20bb0f7f9fab47a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.HostName[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1400,"y":1400,"wires":[["e2f2fdf991dcc1a5"]]},{"id":"c171c7ca5b4813d0","type":"debug","z":"20bb0f7f9fab47a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1450,"y":1480,"wires":[]},{"id":"e2f2fdf991dcc1a5","type":"debug","z":"20bb0f7f9fab47a8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1610,"y":1420,"wires":[]}]
1 Like

thank you!
and sorry for the inconvenience... I'm normally on the discord, it's a bit different there!
If I have questions in the future, I'll try to present a reasonable result right away

You will find if you present data that people can use , you will get more replies and a quicker answer/fix.
We got there in the end and the world is still turning. Hope I have help with your issue and how to ask/present.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.