# Convert string to a format suitable for table

**URL:** https://discourse.nodered.org/t/convert-string-to-a-format-suitable-for-table/97634
**Category:** Dashboard
**Tags:** dashboard-2
**Created:** [15 June 2025 14:31 UTC](https://discourse.nodered.org/t/convert-string-to-a-format-suitable-for-table/97634 "2025-06-15T14:31:36Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![MKaiser96](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MKaiser96](https://discourse.nodered.org/u/MKaiser96)
#### Post date: [15 June 2025 14:31 UTC](https://discourse.nodered.org/t/convert-string-to-a-format-suitable-for-table/97634/1 "2025-06-15T14:31:36Z")

</div>

Hello,

I would like to display the table with the table-node in dashboard 2. I have a string as an input. It looks like:

```auto
Device1:battery low;Device2:communication error;Device3:temperature error

```

How can I automatically convert the string into a format suitable for tables?

It should look like:

```auto
[
    {
        "Device": "Device1",
        "Message": "battery low"
    },
    {
        "Device": "Device2",
        "Message": "communication error"
    },
    {
        "Device": "Device3",
        "Message": "temperature error"
    }
]

```

Best regards

---

<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: [15 June 2025 14:47 UTC](https://discourse.nodered.org/t/convert-string-to-a-format-suitable-for-table/97634/2 "2025-06-15T14:47:43Z")

</div>

> [@MKaiser96](#):
>
> I would like to display the table with the table-node in dashboard 2. I have a string as an input. It looks like:
> 
> ```auto
> Device1:battery low;Device2:communication error;Device3:temperature error
> 
> ```

What makes that string? Is it something you can control (so that it generates a valid JSON or CSV etc?)

---

<div class="post-metadata">

### Author: ![MKaiser96](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MKaiser96](https://discourse.nodered.org/u/MKaiser96)
#### Post date: [15 June 2025 14:51 UTC](https://discourse.nodered.org/t/convert-string-to-a-format-suitable-for-table/97634/3 "2025-06-15T14:51:29Z")

</div>

That string comes out of my smart home system. I don't think that I can control it.

---

<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: [15 June 2025 14:52 UTC](https://discourse.nodered.org/t/convert-string-to-a-format-suitable-for-table/97634/4 "2025-06-15T14:52:37Z")

</div>

OK, if you cannot control or change the input data, then you could use a function node to split it up (there are other ways like JSONata) but here is an example in a function:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/5/1559426963f9845beb1b69569c23a331ab43b4cb.png)

```auto
const inputString = msg.payload
const deviceMessages = inputString.split(';')

const result = deviceMessages.map(deviceMessage => {
    const [device, message] = deviceMessage.split(':')
    return {
        Device: device.trim(),
        Message: message.trim()
    }
})

msg.payload = result
return msg

```

NOTE: I have not taken care of any edge cases or error handling!

---

<div class="post-metadata">

### Author: ![MKaiser96](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MKaiser96](https://discourse.nodered.org/u/MKaiser96)
#### Post date: [15 June 2025 15:01 UTC](https://discourse.nodered.org/t/convert-string-to-a-format-suitable-for-table/97634/5 "2025-06-15T15:01:22Z")

</div>

Thank you very much. The script works exactly as I need it to.

---

<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: [29 June 2025 15:01 UTC](https://discourse.nodered.org/t/convert-string-to-a-format-suitable-for-table/97634/6 "2025-06-29T15:01:56Z")

</div>

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