# Convert serial to object

**URL:** https://discourse.nodered.org/t/convert-serial-to-object/7842
**Category:** General
**Created:** [11 February 2019 17:51 UTC](https://discourse.nodered.org/t/convert-serial-to-object/7842 "2019-02-11T17:51:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![RogierQ](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogierq/32/3211_2.png) [@RogierQ](https://discourse.nodered.org/u/RogierQ)
#### Post date: [11 February 2019 17:51 UTC](https://discourse.nodered.org/t/convert-serial-to-object/7842/1 "2019-02-11T17:51:29Z")

</div>

Hi!

I have a arduino with 4 sensors connected to my pi.  
The serial sends the ouput like below  
{cell\_1:0.01,cell\_2:0.03,cell\_3:-0.02,cell\_4:0.03}

I was hoping that i could use this as an object in my javascript node but thats not wokring  
Also msg.payload.cell\_1 is giving undefined

How can i make this work as an object?  
Or isnt that possible in this way?

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [11 February 2019 18:01 UTC](https://discourse.nodered.org/t/convert-serial-to-object/7842/2 "2019-02-11T18:01:58Z")

</div>

Try sending the serial output through a JSON node. If that fails, you will need to wrap the property names in double quotes when sending.

---

<div class="post-metadata">

### Author: ![RogierQ](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogierq/32/3211_2.png) [@RogierQ](https://discourse.nodered.org/u/RogierQ)
#### Post date: [11 February 2019 18:03 UTC](https://discourse.nodered.org/t/convert-serial-to-object/7842/3 "2019-02-11T18:03:48Z")

</div>

i tried both, that gives me "Unexpected token c in JSON at position 1"

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [11 February 2019 18:06 UTC](https://discourse.nodered.org/t/convert-serial-to-object/7842/4 "2019-02-11T18:06:41Z")

</div>

Your incoming data `msg.payload` should look like:

```json
{"cell_1":0.01,"cell_2":0.03,"cell_3":-0.02,"cell_4":0.03}

```

Use a debug node after the serial-in node to see exactly what you are getting, if it is still failing, post the debug output so we can see the issue.

---

<div class="post-metadata">

### Author: ![RogierQ](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogierq/32/3211_2.png) [@RogierQ](https://discourse.nodered.org/u/RogierQ)
#### Post date: [11 February 2019 18:28 UTC](https://discourse.nodered.org/t/convert-serial-to-object/7842/5 "2019-02-11T18:28:01Z")

</div>

thanks!  
I did this and it works now

```
    Serial.print("{");
Serial.print("\"cell_1\":");
Serial.print(a);
Serial.print(",\"cell_2\":");
Serial.print(b);
Serial.print(",\"cell_3\":");
Serial.print(c);
Serial.print(",\"cell_4\":");
Serial.print(d);
Serial.println("}");
```
