# Convert Object array of SINT's to String

**URL:** <https://discourse.nodered.org/t/convert-object-array-of-sints-to-string/60120>\
**Category:** General\
**Created:** [20 March 2022 18:30 UTC](https://discourse.nodered.org/t/convert-object-array-of-sints-to-string/60120 "2022-03-20T18:30:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![GoEasyOnMe](https://avatars.discourse-cdn.com/v4/letter/g/ad7895/32.png) [@GoEasyOnMe](https://discourse.nodered.org/u/GoEasyOnMe)\
**Post date:** [20 March 2022 18:30 UTC](https://discourse.nodered.org/t/convert-object-array-of-sints-to-string/60120/1 "2022-03-20T18:30:08Z")

</div>

Hi all,

Looking for some help, Using the Node Red Ethernet IP node I have some data coming in the form of an object of SINTs. This is variable length. I want to use a function node to convert this into a String. I've tried a few things but not having much success.

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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [20 March 2022 19:16 UTC](https://discourse.nodered.org/t/convert-object-array-of-sints-to-string/60120/2 "2022-03-20T19:16:03Z")

</div>

Why? You can send it through a json node and that will convert it to a JSON string. You may need to give an example of how you wish this string formatted, if it's not a JSON string you require.

---

<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:** [20 March 2022 19:53 UTC](https://discourse.nodered.org/t/convert-object-array-of-sints-to-string/60120/3 "2022-03-20T19:53:32Z")

</div>

To convert these char values to ascii characters you will need to...

- convert the data into a Buffer
- call Buffer.toString.

This function will do it for you.

```javascript
const values = Object.values(msg.payload)
const buf = Buffer.alloc(values.length)
let pos = 0;
for (let index = 0; index < values.length; index++) {
    const val = values[index];
    if (val <= 0) break
    pos = buf.writeUInt8(val,pos);
}
msg.payload = buf.slice(0,pos).toString()
return msg;

```

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

WARNING:

There is no guarantee an Objects keys will be evaluated in the order you expect. You might have to manipulate the keys and sort the data by the number inside the [square brackets]

---

<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:** [20 March 2022 21:44 UTC](https://discourse.nodered.org/t/convert-object-array-of-sints-to-string/60120/4 "2022-03-20T21:44:45Z")

</div>

Is that exactly how it is coming in? It seems a very strange format. If you are starting with something different and then converting it to that then please show us what you started with. We may be able to suggest a better strategy.

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [21 March 2022 04:31 UTC](https://discourse.nodered.org/t/convert-object-array-of-sints-to-string/60120/5 "2022-03-21T04:31:06Z")

</div>

node-red-contrib-buffer-parser is a handy tool to create a buffer or take values from a buffer. Just a thought.

---

<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 May 2022 04:31 UTC](https://discourse.nodered.org/t/convert-object-array-of-sints-to-string/60120/6 "2022-05-20T04:31:59Z")

</div>

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