# Converting formats

**URL:** <https://discourse.nodered.org/t/converting-formats/82626>\
**Category:** General\
**Created:** [5 November 2023 19:08 UTC](https://discourse.nodered.org/t/converting-formats/82626 "2023-11-05T19:08:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xenos](https://avatars.discourse-cdn.com/v4/letter/x/ea5d25/32.png) [@Xenos](https://discourse.nodered.org/u/Xenos)\
**Post date:** [5 November 2023 19:08 UTC](https://discourse.nodered.org/t/converting-formats/82626/1 "2023-11-05T19:08:50Z")

</div>

I'm not sure if I should be converting from a string to a number or just stripping out some characters.

Any help would be greatly appreciated

![Debug](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/4/c4c611759a6d00c3b5f6661bac27f83532915c16.jpeg)  
.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [5 November 2023 19:19 UTC](https://discourse.nodered.org/t/converting-formats/82626/2 "2023-11-05T19:19:50Z")

</div>

I'm looking at `statusCode` so my guess is, you're using the `HTTP Request` Node?  
if so, set it to output an object

![Screenshot 2023-11-05 at 19.18.29](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1b24858845ef1fb5f7d1199b3f682041473c7f37.png)

not much to go on given your description, but its the best I can do.

---

<div class="post-metadata">

**Author:** ![Xenos](https://avatars.discourse-cdn.com/v4/letter/x/ea5d25/32.png) [@Xenos](https://discourse.nodered.org/u/Xenos)\
**Post date:** [5 November 2023 19:44 UTC](https://discourse.nodered.org/t/converting-formats/82626/3 "2023-11-05T19:44:32Z")

</div>

Yes I am pulling the data using HTTP Request from our hydro utility. If I do set it to JSON I get a parse error, the error is when I'm sending it to a BACnet AV, I can send a standard number, but not this one

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [5 November 2023 19:57 UTC](https://discourse.nodered.org/t/converting-formats/82626/4 "2023-11-05T19:57:13Z")

</div>

Ok, you need to supply the original payload that you receive from the HTTP Request.

Currently, we do not have enough information.  
Please provide payload between that you need to convert between 3 back ticks

````auto
```
Original Payload
```

````

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [5 November 2023 19:58 UTC](https://discourse.nodered.org/t/converting-formats/82626/5 "2023-11-05T19:58:55Z")

</div>

OR as a quick win.

if you are already extracting the ~~number~~ value, convert it before sending to BACnet

```auto
/* Based on your 14,628 MW value */
msg.payload = parseFloat(msg.payload.substring(0,msg.payload.length-3).replace(",","."))
return msg

```

```auto
[{"id":"3ec6499fe536f81c","type":"inject","z":"2d7bf6e3.84c97a","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"14,628 MW","payloadType":"str","x":340,"y":820,"wires":[["02d5ce2081c95338"]]},{"id":"6f43d1a951073d77","type":"debug","z":"2d7bf6e3.84c97a","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":795,"y":820,"wires":[]},{"id":"02d5ce2081c95338","type":"function","z":"2d7bf6e3.84c97a","name":"Convert","func":"/* Based on your 14,628 MW value */\nmsg.payload = parseFloat(msg.payload.substring(0,msg.payload.length-3).replace(\",\",\".\"))\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":525,"y":820,"wires":[["6f43d1a951073d77"]]}]

```

---

<div class="post-metadata">

**Author:** ![Xenos](https://avatars.discourse-cdn.com/v4/letter/x/ea5d25/32.png) [@Xenos](https://discourse.nodered.org/u/Xenos)\
**Post date:** [6 November 2023 02:14 UTC](https://discourse.nodered.org/t/converting-formats/82626/6 "2023-11-06T02:14:26Z")

</div>

Thank you, works perfectly...

---

<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:** [20 November 2023 02:15 UTC](https://discourse.nodered.org/t/converting-formats/82626/7 "2023-11-20T02:15:02Z")

</div>

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