# Filter to get only some data from msg.payload: string

**URL:** https://discourse.nodered.org/t/filter-to-get-only-some-data-from-msg-payload-string/28174
**Category:** General
**Created:** [11 June 2020 12:38 UTC](https://discourse.nodered.org/t/filter-to-get-only-some-data-from-msg-payload-string/28174 "2020-06-11T12:38:00Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![pwgrau](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@pwgrau](https://discourse.nodered.org/u/pwgrau)
#### Post date: [11 June 2020 12:38 UTC](https://discourse.nodered.org/t/filter-to-get-only-some-data-from-msg-payload-string/28174/1 "2020-06-11T12:38:00Z")

</div>

Hello, I have this data via mqtt and I want to take it to an influxdb to graph it in a grafana, the values ​​that arrive in the graph are this whole chain, and I just need to get temperature and humidity data in number:

{"Time":"2020-06-11T13:36:11","SI7021":{"Temperature":15.9,"Humidity":74.5,"DewPoint":11.4},"TempUnit":"C"}

I am a novice in node-red I would appreciate that you explain with what specific nodes I could make these filters.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [11 June 2020 12:50 UTC](https://discourse.nodered.org/t/filter-to-get-only-some-data-from-msg-payload-string/28174/2 "2020-06-11T12:50:41Z")

</div>

Have a read in the node red docs at the section Working with Messages. That should help a lot.  
[Edit] also, if the example you posted is a string then set the MQTT node to output Parsed JSON. It will convert the JSON string to a javascript object which will make it much easier.

---

<div class="post-metadata">

### Author: ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)
#### Post date: [11 June 2020 12:51 UTC](https://discourse.nodered.org/t/filter-to-get-only-some-data-from-msg-payload-string/28174/3 "2020-06-11T12:51:37Z")

</div>

The data is a JSON Object and you can extract the temperature and humidity values using a change node. See the example flow. It is possible that the message from the MQTT node is a JSON string and you will need to add a JSON node to convert the output of the MQTT node to a JSON Object

```auto
[
    {
        "id": "6ff4951.acf306c",
        "type": "tab",
        "label": "Flow 7",
        "disabled": false,
        "info": ""
    },
    {
        "id": "fc5901ca.92592",
        "type": "inject",
        "z": "6ff4951.acf306c",
        "name": "",
        "topic": "",
        "payload": "{\"Time\":\"2020-06-11T13:36:11\",\"SI7021\":{\"Temperature\":15.9,\"Humidity\":74.5,\"DewPoint\":11.4},\"TempUnit\":\"C\"}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 410,
        "y": 140,
        "wires": [
            [
                "b0ba994e.3fe428",
                "1d4f00f9.b6b25f",
                "d316e8b9.a21aa8"
            ]
        ]
    },
    {
        "id": "b0ba994e.3fe428",
        "type": "debug",
        "z": "6ff4951.acf306c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 740,
        "y": 160,
        "wires": []
    },
    {
        "id": "1d4f00f9.b6b25f",
        "type": "change",
        "z": "6ff4951.acf306c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.SI7021.Temperature",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 660,
        "y": 320,
        "wires": [
            [
                "f7bfa24c.9fdeb"
            ]
        ]
    },
    {
        "id": "f7bfa24c.9fdeb",
        "type": "debug",
        "z": "6ff4951.acf306c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 960,
        "y": 340,
        "wires": []
    },
    {
        "id": "d316e8b9.a21aa8",
        "type": "change",
        "z": "6ff4951.acf306c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.SI7021.Humidity",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 680,
        "y": 400,
        "wires": [
            [
                "2bf5fc11.4dba04"
            ]
        ]
    },
    {
        "id": "2bf5fc11.4dba04",
        "type": "debug",
        "z": "6ff4951.acf306c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 920,
        "y": 400,
        "wires": []
    }
]

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [11 June 2020 12:54 UTC](https://discourse.nodered.org/t/filter-to-get-only-some-data-from-msg-payload-string/28174/4 "2020-06-11T12:54:28Z")

</div>

> [@mtoko](#):
>
> you will need to add a JSON node

The MQTT node has this capability built in, just tell it to parse the JSON string and convert it to a javascript object (note, a javascript object, it is not correct to call it a JSON object, JSON is always a string).

---

<div class="post-metadata">

### Author: ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)
#### Post date: [11 June 2020 13:06 UTC](https://discourse.nodered.org/t/filter-to-get-only-some-data-from-msg-payload-string/28174/5 "2020-06-11T13:06:27Z")

</div>

Thanks Colin, always learning! 😊

---

<div class="post-metadata">

### Author: ![pwgrau](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@pwgrau](https://discourse.nodered.org/u/pwgrau)
#### Post date: [11 June 2020 13:08 UTC](https://discourse.nodered.org/t/filter-to-get-only-some-data-from-msg-payload-string/28174/6 "2020-06-11T13:08:59Z")

</div>

I passed it to json I have it as an object and I could remove some data with the change node, I think I have to improve the filter so as not to display and have the pure data I need such as temperature and humidity

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

---

<div class="post-metadata">

### Author: ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)
#### Post date: [11 June 2020 13:52 UTC](https://discourse.nodered.org/t/filter-to-get-only-some-data-from-msg-payload-string/28174/7 "2020-06-11T13:52:20Z")

</div>

![Temp](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/c/ec6391c968adc9cc8f8592d46ca17057771ff36e.jpeg)

---

<div class="post-metadata">

### Author: ![pwgrau](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@pwgrau](https://discourse.nodered.org/u/pwgrau)
#### Post date: [11 June 2020 15:10 UTC](https://discourse.nodered.org/t/filter-to-get-only-some-data-from-msg-payload-string/28174/8 "2020-06-11T15:10:27Z")

</div>

Thank you all very much, it worked that way

---

<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: [25 June 2020 15:10 UTC](https://discourse.nodered.org/t/filter-to-get-only-some-data-from-msg-payload-string/28174/9 "2020-06-25T15:10:27Z")

</div>

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