# Remove "{ }" from payload

**URL:** <https://discourse.nodered.org/t/remove-from-payload/15088>\
**Category:** General\
**Created:** [4 September 2019 09:16 UTC](https://discourse.nodered.org/t/remove-from-payload/15088 "2019-09-04T09:16:50Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Quart666](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quart666/32/12072_2.png) [@Quart666](https://discourse.nodered.org/u/Quart666)\
**Post date:** [4 September 2019 09:16 UTC](https://discourse.nodered.org/t/remove-from-payload/15088/1 "2019-09-04T09:16:50Z")

</div>

Probaly very easy but I have put several housr trying to get his working.  
I am using Weather-Display to publish weather data to my Mosquitto.  
I got this now when doing debug.

WeatherDisplay/temp2 : msg.payload : string[6]

"{12.8}"

I want the payload to be just 12.8 so I can put that value in my MYSQL database.

Please help !

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [4 September 2019 09:20 UTC](https://discourse.nodered.org/t/remove-from-payload/15088/2 "2019-09-04T09:20:31Z")

</div>

Have you thought about using a function node to set msg.payload to a substring starting at position 1 (it’s 0-indexed), and ending at the length of the payload - 1?

---

<div class="post-metadata">

**Author:** ![Quart666](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quart666/32/12072_2.png) [@Quart666](https://discourse.nodered.org/u/Quart666)\
**Post date:** [4 September 2019 09:31 UTC](https://discourse.nodered.org/t/remove-from-payload/15088/3 "2019-09-04T09:31:22Z")

</div>

Thanks for a fast answer !  
I am new to Node red so I need a little more help  
Adding Funtion to flow is no problem but how to write the function is worse  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/900aa5e26be0fd84650e62c319e1485b4cb0d270.png)

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [4 September 2019 09:46 UTC](https://discourse.nodered.org/t/remove-from-payload/15088/4 "2019-09-04T09:46:30Z")

</div>

The function node uses JavaScript to work around the problem programmatically. For this you need basic knowledge of javascript, and a small amount of knowledge on how Node-RED works. Check the following links from the node-red docs: [working with messages](https://nodered.org/docs/user-guide/messages) and [using the function node](https://nodered.org/docs/user-guide/writing-functions).

Beyond that, take a look at [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/String/substring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)

If you follow the concepts described in the working with messages and function node documentation, you should be able to work out the rest with the Mozilla Developer Network link. I'm not going to spoil the answer for you, but you should get it done with 5 lines of code at most. If you work this part out yourself, you can do most basics related to it without (much) help in the future 🙂

---

<div class="post-metadata">

**Author:** ![Quart666](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quart666/32/12072_2.png) [@Quart666](https://discourse.nodered.org/u/Quart666)\
**Post date:** [4 September 2019 11:21 UTC](https://discourse.nodered.org/t/remove-from-payload/15088/5 "2019-09-04T11:21:31Z")

</div>

Thanks, will read those pages and see if I understand more.  
But isnt there anything in Node-Red that can do that witout any programming skills ?

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [4 September 2019 11:34 UTC](https://discourse.nodered.org/t/remove-from-payload/15088/6 "2019-09-04T11:34:26Z")

</div>

> [@Quart666](#):
>
> But isnt there anything in Node-Red that can do that witout any programming skills ?

You can use JSONata syntax in a change node to do the same, setting a substring of that outer string that way. But that requires learning and programming in the JSONata syntax. Here's an example posted to another topic: [Function String Extract - #5 by zenofmud](https://discourse.nodered.org/t/function-string-extract/6775/5)

---

<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:** [4 September 2019 11:36 UTC](https://discourse.nodered.org/t/remove-from-payload/15088/7 "2019-09-04T11:36:00Z")

</div>

Or you could use node-red-contrib-string I think, but it is horrendous overkill. If you want to get the best out of node-red you will need some basic javascript.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [4 September 2019 11:43 UTC](https://discourse.nodered.org/t/remove-from-payload/15088/8 "2019-09-04T11:43:29Z")

</div>

You can use the Change node to remove `{` and `}`

The quotes indicate it's a string rather than a number (as you can see it only has 6 characters)

Set the change node to "change" and then search and replace...

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [4 September 2019 11:54 UTC](https://discourse.nodered.org/t/remove-from-payload/15088/9 "2019-09-04T11:54:44Z")

</div>

So there's three options on how to do this.... I just put together a sample flow to show they all give exactly the same result.

```auto
[{"id":"30adbf39.74344","type":"inject","z":"6d1914f5.165c5c","name":"","topic":"","payload":"{12.8}","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":126.5,"y":177,"wires":[["605798e1.c64338","cbff28e3.cce978","f941b127.ec0f6"]]},{"id":"99637a8d.d5d28","type":"debug","z":"6d1914f5.165c5c","name":"JSONata output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":580.5,"y":178,"wires":[]},{"id":"605798e1.c64338","type":"function","z":"6d1914f5.165c5c","name":"With a function node","func":"msg.payload = msg.payload.substring(1, msg.payload.length - 1)\nreturn msg;","outputs":1,"noerr":0,"x":326.5,"y":239,"wires":[["55e0f225.0010e4"]]},{"id":"55e0f225.0010e4","type":"debug","z":"6d1914f5.165c5c","name":"Function node output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":597.5,"y":239,"wires":[]},{"id":"cbff28e3.cce978","type":"change","z":"6d1914f5.165c5c","name":"With JSONata","rules":[{"t":"set","p":"payload","pt":"msg","to":"$substring(payload, 1, $length(payload) - 2)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":308.5,"y":177,"wires":[["99637a8d.d5d28"]]},{"id":"f941b127.ec0f6","type":"change","z":"6d1914f5.165c5c","name":"With change node/search & replace","rules":[{"t":"change","p":"payload","pt":"msg","from":"{","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"}","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310.5,"y":335,"wires":[["39e2d6eb.e6e86a"]]},{"id":"39e2d6eb.e6e86a","type":"debug","z":"6d1914f5.165c5c","name":"Change node search/replace output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":661.5,"y":336,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Quart666](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quart666/32/12072_2.png) [@Quart666](https://discourse.nodered.org/u/Quart666)\
**Post date:** [4 September 2019 13:06 UTC](https://discourse.nodered.org/t/remove-from-payload/15088/10 "2019-09-04T13:06:22Z")

</div>

Maybe not the best way to do but with my minimal programming skills it solved the problem

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c4dccbabfb2059d3242d2c950fbe2f5fbda4c69b.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d2c3fee3572ca2ea88bc4bd364528b817e99086b.png)

---

<div class="post-metadata">

**Author:** ![nakinigit](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nakinigit/32/44024_2.png) [@nakinigit](https://discourse.nodered.org/u/nakinigit)\
**Post date:** [28 June 2021 22:52 UTC](https://discourse.nodered.org/t/remove-from-payload/15088/11 "2021-06-28T22:52:42Z")

</div>

I think I understand the solutions presented here, but I'm wondering why my solution in a function block does not work:

```auto
var payLoad = msg.payload;
payLoad.replace("}}", "");
payLoad.replace('{', '');
var timeLeft = payLoad.split(':');
msg.payload = timeLeft[3];
return msg;

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 June 2021 23:10 UTC](https://discourse.nodered.org/t/remove-from-payload/15088/12 "2021-06-28T23:10:27Z")

</div>

What does your payload contain & where does it come from (MQTT? HTTP request? Etc?)

Can you screenshot the debug message?

(You can paste a screen snip directly into a reply)

---

<div class="post-metadata">

**Author:** ![nakinigit](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nakinigit/32/44024_2.png) [@nakinigit](https://discourse.nodered.org/u/nakinigit)\
**Post date:** [29 June 2021 18:54 UTC](https://discourse.nodered.org/t/remove-from-payload/15088/13 "2021-06-29T18:54:13Z")

</div>

I have an mqtt input node, with the topic: stat/tasmota/irrigation/RESULT  
The upper portion of this debug window is the unmodified data (before my function node), the lower portion is after my function node.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/8/08f94601c1f41b5a2f33a5e7bb4b1883f46b9819.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [29 June 2021 19:18 UTC](https://discourse.nodered.org/t/remove-from-payload/15088/14 "2021-06-29T19:18:54Z")

</div>

As I suspected, the payload is JSON & therefore can be parsed into a proper object.

I.e, there is zero need to do any string splitting or manipulation.

Set your MQTT in node to return a parsed object.

Then...

There’s a great page in the docs that will explain how to use the debug panel to find the right path to 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)

[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

**Author:** ![nakinigit](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nakinigit/32/44024_2.png) [@nakinigit](https://discourse.nodered.org/u/nakinigit)\
**Post date:** [29 June 2021 20:29 UTC](https://discourse.nodered.org/t/remove-from-payload/15088/15 "2021-06-29T20:29:22Z")

</div>

Oh man, that is so simple! Thank you.
