# "Data types". Stuck getting data formatted correctly

**URL:** https://discourse.nodered.org/t/data-types-stuck-getting-data-formatted-correctly/7780
**Category:** General
**Created:** [9 February 2019 22:33 UTC](https://discourse.nodered.org/t/data-types-stuck-getting-data-formatted-correctly/7780 "2019-02-09T22:33:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [9 February 2019 22:33 UTC](https://discourse.nodered.org/t/data-types-stuck-getting-data-formatted-correctly/7780/1 "2019-02-09T22:33:32Z")

</div>

I'm just not understanding something.

I need to display a simple set of variables in/on a table.  
I found this:  
[Simple One dimensional array.](https://discourse.nodered.org/t/example-template-displaying-a-one-dimensional-table/659/2)  
and it works as given.  
But it takes numbers. But anyway....

The array is rather simple to see/understand.

```auto
var arr =[67.4, 69.5, 72.5, 67.8, 65.0];
msg.payload = arr;
return msg;

```

I want to display this packet in the table.  
(I hacked the code and replaced the first line with the data and it works. So that establishes it can be done.)

This is what I want to display. From a debug node:

```auto
{"topic":"STATUS/WAP/","payload":"[\"TPG-VZBS\", \"Chilli\", \"Tango2\", \"Telstra6C2C0D\", \"WiFi-DFFA\", \"BigPond121C\", \"\", \"NetComm Wireless 2\", \"Fon WiFi\", \"TelstraCCBDD1\"]","qos":2,"retain":false,"_msgid":"6430ff14.59fd3"}

```

To me I see the `msg.paylaod` as:

```auto
["TPG-VZBS", "Chilli", "Tango2", "Telstra6C2C0D", "WiFi-DFFA", "BigPond121C", "", "NetComm Wireless 2", "Fon WiFi", "TelstraCCBDD1"]

```

Which is exactly the same format is the example line.

It doesn't work.

Though in the debug node there is a leading `"` and trailing `"` which I had a devil of a time trying to get rid of.

All to no luck.

This is the code I made to explain what I want to do:

```auto
[{"id":"c752e59.3bf8298","type":"inject","z":"cb1ffcc6.d23ba8","name":"Go","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":110,"y":2010,"wires":[["9369258f.72477"]]},{"id":"9369258f.72477","type":"function","z":"cb1ffcc6.d23ba8","name":"build array (1)","func":"var arr =[67.4, 69.5, 72.5, 67.8, 65.0];\nmsg.payload = arr;\nreturn msg;","outputs":1,"noerr":0,"x":260,"y":2010,"wires":[["43f6ae6f.f5996","2c1e790e.62606e"]]},{"id":"eb665419.25463","type":"inject","z":"cb1ffcc6.d23ba8","name":"Go","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":110,"y":2060,"wires":[["1e7c9821.2b5c4"]]},{"id":"1e7c9821.2b5c4","type":"function","z":"cb1ffcc6.d23ba8","name":"build array (1)","func":"var arr =[\"TPG-VZBS\", \"Chilli\", \"Tango2\", \"Telstra6C2C0D\", \"\", \"BigPond121C\", \"Modem of joy\", \"NetComm Wireless 2\", \"Fon WiFi\", \"TelstraCCBDD1\"];\nmsg.payload = arr;\nreturn msg;","outputs":1,"noerr":0,"x":260,"y":2060,"wires":[["43f6ae6f.f5996","2c1e790e.62606e"]]},{"id":"43f6ae6f.f5996","type":"ui_template","z":"cb1ffcc6.d23ba8","group":"93ff74eb.94d69","name":"One dimension array table USE THIS ONE","order":1,"width":"6","height":"6","format":"<table id=\"table\" border=\"1\">\n <tr>\n <th>Something</th> \n </tr>\n <tbody>\n <tr ng-repeat=\"row in msg.payload\">\n <td class=\"text\" >{{row}}</td>\n </tr>\n </tbody>\n</table>\n","storeOutMessages":false,"fwdInMessages":false,"templateScope":"local","x":600,"y":2010,"wires":[["6abb88fe.9dddb8"]]},{"id":"93ff74eb.94d69","type":"ui_group","z":"","name":"One dimension Array","tab":"9c6bae0.3b358d","order":1,"disp":true,"width":"6","collapse":false},{"id":"9c6bae0.3b358d","type":"ui_tab","z":"","name":"Table Examples","icon":"dashboard","order":1}]

```

That works as is.

But if I get the extra part:

```auto
[{"id":"e2878e.e5d7287","type":"mqtt in","z":"cb1ffcc6.d23ba8","name":"","topic":"STATUS/WAP/#","qos":"2","broker":"8a2e80be.f7c928","x":120,"y":1780,"wires":[["c8dbfab6.c46d3","6ca5d58d.cb0124","19549fd7.1a41f8"]]},{"id":"6ca5d58d.cb0124","type":"string","z":"cb1ffcc6.d23ba8","name":"","methods":[{"name":"delLeftMost","params":[{"type":"str","value":"\""}]},{"name":"delRightMost","params":[{"type":"str","value":"\""}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":100,"y":1840,"wires":[["61112fdc.900548","2faad05c.3ebf7"]]},{"id":"2faad05c.3ebf7","type":"function","z":"cb1ffcc6.d23ba8","name":"","func":"var x = '[' + msg.payload + ']';\nmsg.payload = x;\nreturn msg;\n","outputs":1,"noerr":0,"x":290,"y":1880,"wires":[["e6014a54.116168","43f6ae6f.f5996"]]},{"id":"43f6ae6f.f5996","type":"ui_template","z":"cb1ffcc6.d23ba8","group":"93ff74eb.94d69","name":"One dimension array table USE THIS ONE","order":1,"width":"6","height":"6","format":"<table id=\"table\" border=\"1\">\n <tr>\n <th>Something</th> \n </tr>\n <tbody>\n <tr ng-repeat=\"row in msg.payload\">\n <td class=\"text\" >{{row}}</td>\n </tr>\n </tbody>\n</table>\n","storeOutMessages":false,"fwdInMessages":false,"templateScope":"local","x":600,"y":2010,"wires":[["6abb88fe.9dddb8"]]},{"id":"8a2e80be.f7c928","type":"mqtt-broker","z":"","name":"MQTT host","broker":"192.168.0.99","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"ARDUINO_STATUS","birthQos":"2","birthPayload":"connected","willTopic":"ARDUINO_STATUS","willQos":"2","willPayload":"disconnected"},{"id":"93ff74eb.94d69","type":"ui_group","z":"","name":"One dimension Array","tab":"9c6bae0.3b358d","order":1,"disp":true,"width":"6","collapse":false},{"id":"9c6bae0.3b358d","type":"ui_tab","z":"","name":"Table Examples","icon":"dashboard","order":1}]

```

(You can see the overlap)

It doesn't work when the packet arrives.

The `string` node is there to **try** and fix up the formatting, but it really isn't working.

.

Yes. I know I have asked about this sort of stuff before.  
I **do** want to understand it. But, for what ever reason, I am simply not understanding it.

I've been called up a few times (and I don't mind) about my "text formatting" and how I sometimes _over do it_ with capitols, italics, etc etc.

I admit, that is a corrupt way of doing it. But it **is** something like how I was shown _back in the day_.

Nowadays, the style of _markup_ blows my mind. To me it is gibberish.

I have to read things about 4 times before they even start to make sense. So when I read some stuff I am completely out of my depth.

Sure: That's how it is. Like it or lump it. But I don't really subscribe to that mentality.  
We are all different. Because someone things differently doen't mean they are _wrong_. They are simply _different_.

So, I would like some help with understanding what I am not understanding, and please believe me when I say I don't like asking for help like this.  
I get that **I should be able to work it out for myself.** I can sit there for hours repeating the example.

THERE AND THEN, it makes sense.

Next time...... It doesn't.

That's who I am.  
And I have to live with this condition every hour of every day, all my life.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [9 February 2019 22:58 UTC](https://discourse.nodered.org/t/data-types-stuck-getting-data-formatted-correctly/7780/2 "2019-02-09T22:58:42Z")

</div>

> [@Trying\_to\_learn](#):
>
> To me I see the `msg.paylaod` as:
> 
> ```auto
> ["TPG-VZBS", "Chilli", "Tango2", "Telstra6C2C0D", "WiFi-DFFA", "BigPond121C", "", "NetComm Wireless 2", "Fon WiFi", "TelstraCCBDD1"]
> 
> ```
> 
> ...  
> Though in the debug node there is a leading `"` and trailing `"` which I had a devil of a time trying to get rid of.

The extra quotes when displayed in Debug tells you that `msg.payload` is a String. Its a piece of text that looks like an array of strings.

In your flow you need an actual array of strings, not a piece of text that looks like one.

You can get rid of the `String` node you've added and replace it with a `JSON` node. The JSON node will take the msg.payload that is a string that _looks like an array_ and convert it to the actual array object.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [9 February 2019 23:01 UTC](https://discourse.nodered.org/t/data-types-stuck-getting-data-formatted-correctly/7780/3 "2019-02-09T23:01:57Z")

</div>

Ah! That's right!

`json` node!

Now I remember. And I know that will sound _cheesy_ or _cliche_, but......

Again: Thanks.
