# Splitting up API Oject Array

**URL:** <https://discourse.nodered.org/t/splitting-up-api-oject-array/90862>\
**Category:** General\
**Created:** [10 September 2024 17:47 UTC](https://discourse.nodered.org/t/splitting-up-api-oject-array/90862 "2024-09-10T17:47:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanprel](https://avatars.discourse-cdn.com/v4/letter/r/7c8e57/32.png) [@ryanprel](https://discourse.nodered.org/u/ryanprel)\
**Post date:** [10 September 2024 17:47 UTC](https://discourse.nodered.org/t/splitting-up-api-oject-array/90862/1 "2024-09-10T17:47:21Z")

</div>

I'm looking for some help with fleshing out a flow. The background: Rapt is a company that produces digital hydrometers that float in a tank and check sugar levels that I use for monitoring fermentations in about 17 different tanks, some simultaneously. I have used webhooks in the past but they're pretty unreliable and since they have an API, I'd prefer using that. Using the below flow, I get the attached screenshot results. I'd like to segment these out and send each independent tank information to the proper dashboard components for that tank, all based on the name used in each object returned with the API request. Does anyone have an example of how to do something similar that I can work from?

 ![Screenshot 2024-09-10 at 12.13.57 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/c/4c64e94fd30909166b6ecb08052d8d255f70cb63.png)

```auto
[
    {
        "id": "910122750895da49",
        "type": "debug",
        "z": "15f71001.075b9",
        "name": "debug 32",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 2160,
        "wires": []
    },
    {
        "id": "959053dd05d1dee1",
        "type": "rapt-pull",
        "z": "15f71001.075b9",
        "account": "",
        "name": "Pills",
        "endpoint": "GetHydrometers",
        "topic": "",
        "split": false,
        "x": 270,
        "y": 2160,
        "wires": [
            [
                "719872fe65dd71b6"
            ]
        ]
    },
    {
        "id": "b6ad4230c91f7ddf",
        "type": "inject",
        "z": "15f71001.075b9",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 140,
        "y": 2160,
        "wires": [
            [
                "959053dd05d1dee1"
            ]
        ]
    },
    {
        "id": "719872fe65dd71b6",
        "type": "split",
        "z": "15f71001.075b9",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 390,
        "y": 2160,
        "wires": [
            [
                "910122750895da49"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [10 September 2024 18:13 UTC](https://discourse.nodered.org/t/splitting-up-api-oject-array/90862/2 "2024-09-10T18:13:30Z")

</div>

The data you have shown us [a picture of] is not an array but an object.

The difference is that an array contains a sequence of values:

```auto
[17.71, 67.804706, 13.8208]

```

while an object also has keys to identify each value

```auto
{"temperature": 17.71, "gravity": 67.804706, "battery": 13.8208}

```

You can refer to these values by their key.

```auto
msg.payload.gravity

```

It looks like you want to direct the messages according to msg.payload.name like this

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/f/7faa5d24dcfb61dd712daaefe70df9d0f64e2fc1.png)

---

<div class="post-metadata">

**Author:** ![ryanprel](https://avatars.discourse-cdn.com/v4/letter/r/7c8e57/32.png) [@ryanprel](https://discourse.nodered.org/u/ryanprel)\
**Post date:** [10 September 2024 18:31 UTC](https://discourse.nodered.org/t/splitting-up-api-oject-array/90862/3 "2024-09-10T18:31:04Z")

</div>

The name would be the unique-ID here (or the MAC address but name is easier to track and is unique). The data actually comes in as an array first but the split node segments it up into individual objects. It looks like a switch node might do the trick for me - thanks for the assist!

 ![Screenshot 2024-09-10 at 1.27.42 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3f39d73d4752ee7e2da9a10f89bbf6ac7d1a6cee.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [10 September 2024 19:02 UTC](https://discourse.nodered.org/t/splitting-up-api-oject-array/90862/4 "2024-09-10T19:02:45Z")

</div>

You would split the array, then assign the name (or mac) to a msg.property (msg.topic) you can then split the object. You can then use two switch nodes to route by msg.topic(name) and msg.parts.key(object key) to the dashboard nodes you wish.  
e.g.

```auto
[{"id":"b6ad4230c91f7ddf","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"name\":\"pill-1\",\"temp\":20,\"gravity\":60},{\"name\":\"pill-2\",\"temp\":22,\"gravity\":62},{\"name\":\"pill-3\",\"temp\":23,\"gravity\":63}]","payloadType":"json","x":130,"y":2740,"wires":[["719872fe65dd71b6"]]},{"id":"719872fe65dd71b6","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":250,"y":2740,"wires":[["4bdac1700cc016e4"]]},{"id":"4bdac1700cc016e4","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload.name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":2740,"wires":[["236174b293100639"]]},{"id":"236174b293100639","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":170,"y":2840,"wires":[["d478d12436bb33f6"]]},{"id":"d478d12436bb33f6","type":"switch","z":"d1395164b4eec73e","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"pill-1","vt":"str"},{"t":"eq","v":"pill-2","vt":"str"},{"t":"eq","v":"pill-3","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":310,"y":2840,"wires":[["ae4caa4e8b30f31a"],["2341b6d24041e7f0"],["cc3caef94484ef38"]]},{"id":"ae4caa4e8b30f31a","type":"switch","z":"d1395164b4eec73e","name":"","property":"parts.key","propertyType":"msg","rules":[{"t":"eq","v":"name","vt":"str"},{"t":"eq","v":"temp","vt":"str"},{"t":"eq","v":"gravity","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":510,"y":2800,"wires":[["910122750895da49"],["91b961eb9b086c1c"],["e34d09a70b2ef782"]]},{"id":"2341b6d24041e7f0","type":"switch","z":"d1395164b4eec73e","name":"","property":"parts.key","propertyType":"msg","rules":[{"t":"eq","v":"name","vt":"str"},{"t":"eq","v":"temp","vt":"str"},{"t":"eq","v":"gravity","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":510,"y":2920,"wires":[["7413f0a978a44f1f"],["5e39f253656b56cf"],["aae1b702a7d1d477"]]},{"id":"cc3caef94484ef38","type":"switch","z":"d1395164b4eec73e","name":"","property":"parts.key","propertyType":"msg","rules":[{"t":"eq","v":"name","vt":"str"},{"t":"eq","v":"temp","vt":"str"},{"t":"eq","v":"gravity","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":510,"y":3040,"wires":[["c4d5dbbf069882cf"],["c77f0f4ddb9e288f"],["81ef4a5cf1cd1492"]]},{"id":"910122750895da49","type":"debug","z":"d1395164b4eec73e","name":"name","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":2780,"wires":[]},{"id":"91b961eb9b086c1c","type":"debug","z":"d1395164b4eec73e","name":"temp","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":2820,"wires":[]},{"id":"e34d09a70b2ef782","type":"debug","z":"d1395164b4eec73e","name":"gravity","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":2860,"wires":[]},{"id":"7413f0a978a44f1f","type":"debug","z":"d1395164b4eec73e","name":"name","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":2900,"wires":[]},{"id":"5e39f253656b56cf","type":"debug","z":"d1395164b4eec73e","name":"temp","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":2940,"wires":[]},{"id":"aae1b702a7d1d477","type":"debug","z":"d1395164b4eec73e","name":"gravity","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":2980,"wires":[]},{"id":"c4d5dbbf069882cf","type":"debug","z":"d1395164b4eec73e","name":"name","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":3020,"wires":[]},{"id":"c77f0f4ddb9e288f","type":"debug","z":"d1395164b4eec73e","name":"temp","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":3060,"wires":[]},{"id":"81ef4a5cf1cd1492","type":"debug","z":"d1395164b4eec73e","name":"gravity","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":3100,"wires":[]}]

```

 ![chrome_screenshot_10 Sep 2024 20_03_59 BST](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/8/f864692e6d92ef704f461caf02b3f1f30ecb56d2.png)

p.s. Please share data in text format not as a picture. It makes it easier for others to help you. preferably in an inject node as people can then just hit the inject and run your data.

There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path/value for any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [9 December 2024 19:03 UTC](https://discourse.nodered.org/t/splitting-up-api-oject-array/90862/5 "2024-12-09T19:03:43Z")

</div>

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