Extract from array ,object

Need some help to extract form an Object

2/16/2024, 10:20:06 AM[node: debug 90](http://127.0.0.1:1880/#)

msg.payload : array[1]

array[1]

0: object

intemp: "81.1"

unit: "F"

inhumi: "38%"

abs: "29.95 inHg"

rel: "29.95 inHg"

Need to extract the values for intemo,inhumi,abs,arel
individual to display as a text.

[
    {
        "id": "7da2e023f84a2dcc",
        "type": "inject",
        "z": "f464957002a4d7f4",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 140,
        "wires": [
            [
                "38dcf0f25307b8ab"
            ]
        ]
    },
    {
        "id": "38dcf0f25307b8ab",
        "type": "http request",
        "z": "f464957002a4d7f4",
        "name": "",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "http://10.0.4.54/get_livedata_info?",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 290,
        "y": 240,
        "wires": [
            [
                "3bc27ec8fbe07fca"
            ]
        ]
    },
    {
        "id": "3bc27ec8fbe07fca",
        "type": "split",
        "z": "f464957002a4d7f4",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 470,
        "y": 220,
        "wires": [
            [
                "3e2fe869e378fa50",
                "bd2a9c7d2f5272ea"
            ]
        ]
    },
    {
        "id": "3e2fe869e378fa50",
        "type": "debug",
        "z": "f464957002a4d7f4",
        "name": "debug 90",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 660,
        "y": 160,
        "wires": []
    },
    {
        "id": "a0da53b7dd6d2f89",
        "type": "ui_text",
        "z": "f464957002a4d7f4",
        "group": "241820d172e65d1d",
        "order": 22,
        "width": 0,
        "height": 0,
        "name": "",
        "label": "text",
        "format": "{{msg.payload[0].intemp}}",
        "layout": "row-spread",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 890,
        "y": 180,
        "wires": []
    },
    {
        "id": "bd2a9c7d2f5272ea",
        "type": "function",
        "z": "f464957002a4d7f4",
        "name": "function 15",
        "func": "msg.payload.intemp\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 670,
        "y": 220,
        "wires": [
            [
                "a0da53b7dd6d2f89"
            ]
        ]
    },
    {
        "id": "241820d172e65d1d",
        "type": "ui_group",
        "name": "MAIN POWER",
        "tab": "76c1d76e82d63ff5",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "76c1d76e82d63ff5",
        "type": "ui_tab",
        "name": "OBS",
        "icon": "dashboard",
        "order": 2,
        "disabled": false,
        "hidden": false
    }
]

This Is what I am working on

Thanks

Hi, i have updated your post for readability and to prevent the forum making your flow un-importable.

In future, please use the copy value button to copy good format data from messages and payloads - shown when you over hover a debug message property in the sidebar.

BX00Cy7yHi

Also, always wrap data/code/flows/logs in a code block

```
code here between three backticks
```

I'm not convinced that you need the split node.

Move your debug node to the output of your http request. Then, as @Steve-Mcl shows, you can find the path to the element[s] you want.
I think, for example, temperature is at msg.payload[0].intemp

In your function node you have this

msg.payload.intemp
return msg;

Just the name of element msg.payload.intemp, even if it exists, does nothing with it.

Could it be that you wanted something like this? (Look, no functions!)

1 Like

Are the Change nodes even needed, You could just use {{msg.payload[0].intemp}} or {{msg.payload[0].inhumi}} in the text nodes.

But as jbudd says, show the output of the http request node, so we can all be sure of the exact data.

2 Likes

Nope, change nodes not needed. Mind you, my illustration would be less self explanatory without them!

Debatable, you could name the text nodes similarly to the way you did with the change nodes.

If i'd have thunk of that i'd have dun it! :worried:

3 Likes

Thansk to all I was close, but your knowledge is super

1 Like

jbudd

I add another sensor and now I received this object, Can you Please help me out to be able to display object 4,5,6,7. Thanks In advance for your time

/16/2024, 12:25:35 PMnode: debug 90

msg.payload : array[10]

array[10]

0: object

1: object

2: object

3: object

4: object

id: "0x0B"

val: "0.00 mph"

5: object

id: "0x0C"

val: "0.00 mph"

6: object

id: "0x19"

val: "17.22 mph"

7: object

id: "0x15"

val: "2.21 W/m2"

As i said before...

Sorry, I think now that I may get what you said.Let me know is this is good.

[
  {"id":"0x02","val":"--.-","unit":"F"},
  {"id":"0x07","val":"--"},
  {"id":"3","val":"--.-","unit":"F"},
  {"id":"0x03","val":"--.-","unit":"F"},
  {"id":"0x0B","val":"0.00 mph"},
  {"id":"0x0C","val":"0.00 mph"},
  {"id":"0x19","val":"17.22 mph"},
  {"id":"0x15","val":"1.74 W/m2"},
  {"id":"0x17","val":"0"},
  {"id":"0x0A","val":"228","battery":"5"}
]

I copy the value of the object, or I need to do it individual like this

{"id":"0x0B","val":"0.00 mph"}

Luis RIvera


Admin edit: wrap code in ``` code block ```

I thought we had given you sound advice before.

Two possible routes depending on if the array of object always has the same order.

I think you would gain some more insight into node-red if you watched these essentials videos

Example flows

[{"id":"1b77de4539b79cb2","type":"debug","z":"d1395164b4eec73e","name":"msg.payload.val","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload.val","targetType":"msg","statusVal":"payload","statusType":"auto","x":820,"y":5460,"wires":[]},{"id":"e8f3faaab5afb0df","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":550,"y":5340,"wires":[["ad03663e3fc51aa7"]]},{"id":"54e60a80d26d8c2b","type":"inject","z":"d1395164b4eec73e","name":"if order can be different","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"id\":\"0x03\",\"val\":\"--.-\",\"unit\":\"F\"},{\"id\":\"0x0B\",\"val\":\"0.00 mph\"},{\"id\":\"0x0C\",\"val\":\"0.00 mph\"},{\"id\":\"0x19\",\"val\":\"17.22 mph\"},{\"id\":\"0x15\",\"val\":\"1.74 W/m2\"},{\"id\":\"0x02\",\"val\":\"--.-\",\"unit\":\"F\"},{\"id\":\"0x07\",\"val\":\"--\"},{\"id\":\"3\",\"val\":\"--.-\",\"unit\":\"F\"},{\"id\":\"0x17\",\"val\":\"0\"},{\"id\":\"0x0A\",\"val\":\"228\",\"battery\":\"5\"}]","payloadType":"json","x":380,"y":5340,"wires":[["e8f3faaab5afb0df"]]},{"id":"e42d18a01a6e78b5","type":"inject","z":"d1395164b4eec73e","name":"Array order always the same","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[   {\"id\":\"0x02\",\"val\":\"--.-\",\"unit\":\"F\"},   {\"id\":\"0x07\",\"val\":\"--\"},   {\"id\":\"3\",\"val\":\"--.-\",\"unit\":\"F\"},   {\"id\":\"0x03\",\"val\":\"--.-\",\"unit\":\"F\"},   {\"id\":\"0x0B\",\"val\":\"0.00 mph\"},   {\"id\":\"0x0C\",\"val\":\"0.00 mph\"},   {\"id\":\"0x19\",\"val\":\"17.22 mph\"},   {\"id\":\"0x15\",\"val\":\"1.74 W/m2\"},   {\"id\":\"0x17\",\"val\":\"0\"},   {\"id\":\"0x0A\",\"val\":\"228\",\"battery\":\"5\"} ]","payloadType":"json","x":400,"y":5220,"wires":[["ea8c8eae791a06dd","6d4a0b42074decfe","13625d0488d2850b"]]},{"id":"ea8c8eae791a06dd","type":"debug","z":"d1395164b4eec73e","name":"msg.payload[4].val","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload[4].val","targetType":"msg","statusVal":"payload[4].val","statusType":"auto","x":630,"y":5160,"wires":[]},{"id":"6d4a0b42074decfe","type":"debug","z":"d1395164b4eec73e","name":"msg.payload[5].val","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload[5].val","targetType":"msg","statusVal":"payload[4].val","statusType":"auto","x":630,"y":5220,"wires":[]},{"id":"13625d0488d2850b","type":"debug","z":"d1395164b4eec73e","name":"msg.payload[6].val","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload[6].val","targetType":"msg","statusVal":"payload[4].val","statusType":"auto","x":630,"y":5280,"wires":[]},{"id":"ad03663e3fc51aa7","type":"switch","z":"d1395164b4eec73e","name":"route on msg.payload.id","property":"payload.id","propertyType":"msg","rules":[{"t":"eq","v":"0x0B","vt":"num"},{"t":"eq","v":"0x0C","vt":"str"},{"t":"eq","v":"0x19","vt":"str"}],"checkall":"false","repair":false,"outputs":3,"x":570,"y":5400,"wires":[["fcbf5eb9b794a3fb"],["dc6a916b731cde9d"],["1b77de4539b79cb2"]]},{"id":"fcbf5eb9b794a3fb","type":"debug","z":"d1395164b4eec73e","name":"msg.payload.val","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload.val","targetType":"msg","statusVal":"payload","statusType":"auto","x":820,"y":5340,"wires":[]},{"id":"dc6a916b731cde9d","type":"debug","z":"d1395164b4eec73e","name":"msg.payload.val","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload.val","targetType":"msg","statusVal":"error_count","statusType":"auto","x":820,"y":5400,"wires":[]}]

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