# Convert buffer into string and then json

**URL:** <https://discourse.nodered.org/t/convert-buffer-into-string-and-then-json/81774>\
**Category:** General\
**Created:** [4 October 2023 15:55 UTC](https://discourse.nodered.org/t/convert-buffer-into-string-and-then-json/81774 "2023-10-04T15:55:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Romprod](https://avatars.discourse-cdn.com/v4/letter/r/e47774/32.png) [@Romprod](https://discourse.nodered.org/u/Romprod)\
**Post date:** [4 October 2023 15:55 UTC](https://discourse.nodered.org/t/convert-buffer-into-string-and-then-json/81774/1 "2023-10-04T15:55:54Z")

</div>

Hi,

I'm trying to use NodeRed to parse data coming into NodeRed via a webhook.

When sending a test to NodeRed I get the following as a buffer

```auto
[45,45,101,55,100,101,56,56,56,102,45,48,98,51,54,45,52,99,48,50,45,57,100,54,98,45,99,57,48,97,98,98,55,101,101,54,56,51,13,10,67,111,110,116,101,110,116,45,84,121,112,101,58,32,97,112,112,108,105,99,97,116,105,111,110,47,106,115,111,110,59,32,99,104,97,114,115,101,116,61,117,116,102,45,56,13,10,67,111,110,116,101,110,116,45,68,105,115,112,111,115,105,116,105,111,110,58,32,102,111,114,109,45,100,97,116,97,59,32,110,97,109,101,61,100,97,116,97,13,10,13,10,123,34,84,105,116,108,101,34,58,34,84,101,115,116,32,78,111,116,105,102,105,99,97,116,105,111,110,34,44,34,68,101,115,99,114,105,112,116,105,111,110,34,58,34,84,101,115,116,32,78,111,116,105,102,105,99,97,116,105,111,110,32,68,101,115,99,114,105,112,116,105,111,110,34,44,34,68,97,116,101,34,58,34,50,48,50,51,45,49,48,45,48,52,84,49,53,58,50,49,58,52,51,46,49,50,52,56,55,55,56,90,34,44,34,69,118,101,110,116,34,58,34,115,121,115,116,101,109,46,119,101,98,104,111,111,107,116,101,115,116,34,44,34,83,101,114,118,101,114,34,58,123,34,78,97,109,101,34,58,34,69,109,98,121,86,49,34,44,34,73,100,34,58,34,57,52,56,102,51,97,98,54,98,99,57,97,52,102,48,100,57,101,97,99,101,52,53,55,56,102,56,102,98,48,98,54,34,44,34,86,101,114,115,105,111,110,34,58,34,52,46,55,46,49,52,46,48,34,125,125,13,10,45,45,101,55,100,101,56,56,56,102,45,48,98,51,54,45,52,99,48,50,45,57,100,54,98,45,99,57,48,97,98,98,55,101,101,54,56,51,45,45,13,10]

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/4/4421a1ee9135d0c5ea3ce8f0c89474c8873b77a9.png)

And the raw version is this

```auto
--e7de888f-0b36-4c02-9d6b-c90abb7ee683
Content-Type: application/json; charset=utf-8
Content-Disposition: form-data; name=data

{"Title":"Test Notification","Description":"Test Notification Description","Date":"2023-10-04T15:21:43.1248778Z","Event":"system.webhooktest","Server":{"Name":"EmbyV1","Id":"948f3ab6bc9a4f0d9eace4578f8fb0b6","Version":"4.7.14.0"}}
--e7de888f-0b36-4c02-9d6b-c90abb7ee683--

```

But I'd like to convert it into a string (to get rid of the top 4 lines) and then convert to JSON

I've tried using node-red-contrib-buffer-parser 3.22 but honestly I'm lost as to which options that I need.

Test flow export

```auto
[{"id":"7d8a97b45e1b69c9","type":"inject","z":"b1dcf7684deceb7b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[45,45,101,55,100,101,56,56,56,102,45,48,98,51,54,45,52,99,48,50,45,57,100,54,98,45,99,57,48,97,98,98,55,101,101,54,56,51,13,10,67,111,110,116,101,110,116,45,84,121,112,101,58,32,97,112,112,108,105,99,97,116,105,111,110,47,106,115,111,110,59,32,99,104,97,114,115,101,116,61,117,116,102,45,56,13,10,67,111,110,116,101,110,116,45,68,105,115,112,111,115,105,116,105,111,110,58,32,102,111,114,109,45,100,97,116,97,59,32,110,97,109,101,61,100,97,116,97,13,10,13,10,123,34,84,105,116,108,101,34,58,34,84,101,115,116,32,78,111,116,105,102,105,99,97,116,105,111,110,34,44,34,68,101,115,99,114,105,112,116,105,111,110,34,58,34,84,101,115,116,32,78,111,116,105,102,105,99,97,116,105,111,110,32,68,101,115,99,114,105,112,116,105,111,110,34,44,34,68,97,116,101,34,58,34,50,48,50,51,45,49,48,45,48,52,84,49,53,58,50,49,58,52,51,46,49,50,52,56,55,55,56,90,34,44,34,69,118,101,110,116,34,58,34,115,121,115,116,101,109,46,119,101,98,104,111,111,107,116,101,115,116,34,44,34,83,101,114,118,101,114,34,58,123,34,78,97,109,101,34,58,34,69,109,98,121,86,49,34,44,34,73,100,34,58,34,57,52,56,102,51,97,98,54,98,99,57,97,52,102,48,100,57,101,97,99,101,52,53,55,56,102,56,102,98,48,98,54,34,44,34,86,101,114,115,105,111,110,34,58,34,52,46,55,46,49,52,46,48,34,125,125,13,10,45,45,101,55,100,101,56,56,56,102,45,48,98,51,54,45,52,99,48,50,45,57,100,54,98,45,99,57,48,97,98,98,55,101,101,54,56,51,45,45,13,10]","payloadType":"bin","x":170,"y":160,"wires":[["e29b35f75a4ebbe8"]]},{"id":"e29b35f75a4ebbe8","type":"debug","z":"b1dcf7684deceb7b","name":"debug 395","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":390,"y":160,"wires":[]}]

```

---

<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:** [4 October 2023 16:46 UTC](https://discourse.nodered.org/t/convert-buffer-into-string-and-then-json/81774/2 "2023-10-04T16:46:25Z")

</div>

> [@Romprod](#):
>
> I've tried using node-red-contrib-buffer-parser 3.22 but honestly I'm lost as to which options that I need

That node is more for extracting bits and bytes and number conversions (though it can convert the data to a string for you - it is just overkill).

You need simple buffer-\>string and a JSON node.

In a function, you can do something like

```auto
const str = msg.payload.toString() // convert buffer to string
const split = str.split('\r\n') // convert to an array of lines
msg.payload = split[4] // pick the 4th line
return msg

```

_untested_

so long as `msg.payload` IS a buffer

then pass the msg through a JSON node to make a pretty/usable object.

NOTE: It would be far better is the webhook only sent the data in the payload. Are you using built in the HTTP-in node for intercepting the webhook?

---

<div class="post-metadata">

**Author:** ![Romprod](https://avatars.discourse-cdn.com/v4/letter/r/e47774/32.png) [@Romprod](https://discourse.nodered.org/u/Romprod)\
**Post date:** [5 October 2023 07:33 UTC](https://discourse.nodered.org/t/convert-buffer-into-string-and-then-json/81774/3 "2023-10-05T07:33:47Z")

</div>

This works perfectly, thanks.

```const
const split = str.split('\r\n') // convert to an array of lines
msg.payload = split[4] // pick the 4th line
return msg

```

> It would be far better is the webhook only sent the data in the payload

Agreed

> Are you using built in the HTTP-in node for intercepting the webhook?

Yup

---

<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:** [19 October 2023 07:34 UTC](https://discourse.nodered.org/t/convert-buffer-into-string-and-then-json/81774/4 "2023-10-19T07:34:24Z")

</div>

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