# Extract data from msg.payload.response

**URL:** https://discourse.nodered.org/t/extract-data-from-msg-payload-response/58664
**Category:** General
**Created:** [19 February 2022 19:52 UTC](https://discourse.nodered.org/t/extract-data-from-msg-payload-response/58664 "2022-02-19T19:52:07Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![old-hell](https://avatars.discourse-cdn.com/v4/letter/o/4491bb/32.png) [@old-hell](https://discourse.nodered.org/u/old-hell)
#### Post date: [19 February 2022 19:52 UTC](https://discourse.nodered.org/t/extract-data-from-msg-payload-response/58664/1 "2022-02-19T19:52:07Z")

</div>

Hi, Id like to extract an integer from a msg.payload.response

I just need the power data. tried many functions, but don't get it.  
can someone help me out here?

this is the payload result:

{  
"power": 3.037565,  
"relay": true  
}

best regards  
Jens

---

<div class="post-metadata">

### Author: ![SandeepA](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sandeepa/32/63225_2.png) [@SandeepA](https://discourse.nodered.org/u/SandeepA)
#### Post date: [19 February 2022 19:53 UTC](https://discourse.nodered.org/t/extract-data-from-msg-payload-response/58664/2 "2022-02-19T19:53:26Z")

</div>

Is the response from http - whats the format ? UTF or JSON object ? Did you try to converting it to JSON object. Then should be straight forward.

---

<div class="post-metadata">

### Author: ![old-hell](https://avatars.discourse-cdn.com/v4/letter/o/4491bb/32.png) [@old-hell](https://discourse.nodered.org/u/old-hell)
#### Post date: [19 February 2022 20:18 UTC](https://discourse.nodered.org/t/extract-data-from-msg-payload-response/58664/3 "2022-02-19T20:18:40Z")

</div>

I think its a http response. I'm totally new in node-red and java js. dont know how to convert it to a JSON object.

when using this command in bash, i get the power data:  
curl [http://192.168.0.86/report](http://192.168.0.86/report) | sed -n 2p | awk 'NF\>1{print $NF}' | sed 's/.$//'

this is the complete msg.payload i get, when using the mystrom plugin.

![Bildschirmfoto 2022-02-19 um 21.09.42](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/9/994f54f879364a4c62ee6429c2d7806f3591efb1.png)

---

<div class="post-metadata">

### Author: ![SandeepA](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sandeepa/32/63225_2.png) [@SandeepA](https://discourse.nodered.org/u/SandeepA)
#### Post date: [19 February 2022 20:21 UTC](https://discourse.nodered.org/t/extract-data-from-msg-payload-response/58664/4 "2022-02-19T20:21:00Z")

</div>

Ok. It may/may not be http.  
You need to send it to JSON node to convert it to JSON object.  
In json node - configure - the value as msg.payload.response and setting as Convert to JSON Object.  
Should work.

---

<div class="post-metadata">

### Author: ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)
#### Post date: [19 February 2022 20:25 UTC](https://discourse.nodered.org/t/extract-data-from-msg-payload-response/58664/5 "2022-02-19T20:25:31Z")

</div>

First use a change node and set the payload to payload.response. With this feed the json node and the get the value by extracting the power.

```auto
[
    {
        "id": "3c52b18925bace22",
        "type": "change",
        "z": "ebe8134f6b5af26c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.response",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 450,
        "y": 1360,
        "wires": [
            [
                "b87e294ee7801cb8"
            ]
        ]
    },
    {
        "id": "b87e294ee7801cb8",
        "type": "json",
        "z": "ebe8134f6b5af26c",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 650,
        "y": 1360,
        "wires": [
            [
                "89193357b0838718"
            ]
        ]
    },
    {
        "id": "89193357b0838718",
        "type": "change",
        "z": "ebe8134f6b5af26c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.power",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 850,
        "y": 1360,
        "wires": [
            [
                "759c0e7163544516"
            ]
        ]
    },
    {
        "id": "759c0e7163544516",
        "type": "debug",
        "z": "ebe8134f6b5af26c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1080,
        "y": 1360,
        "wires": []
    },
    {
        "id": "ef1f93c641c49c47",
        "type": "inject",
        "z": "ebe8134f6b5af26c",
        "name": "",
        "props": [
            {
                "p": "payload.response",
                "v": "{\"power\":2123}",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 250,
        "y": 1360,
        "wires": [
            [
                "3c52b18925bace22"
            ]
        ]
    }
]

```

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

---

<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: [5 March 2022 20:25 UTC](https://discourse.nodered.org/t/extract-data-from-msg-payload-response/58664/6 "2022-03-05T20:25:57Z")

</div>

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