# Array Split trouble

**URL:** https://discourse.nodered.org/t/array-split-trouble/56041
**Category:** General
**Created:** [3 January 2022 14:43 UTC](https://discourse.nodered.org/t/array-split-trouble/56041 "2022-01-03T14:43:48Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)
#### Post date: [3 January 2022 14:43 UTC](https://discourse.nodered.org/t/array-split-trouble/56041/1 "2022-01-03T14:43:49Z")

</div>

I am having trouble splitting an array and converting result to a number as follows.  
the main array consists of 185 elements  
I can split the main array into the element I want with the following ...

```auto
var parts = msg.payload.split(",");
    msg.payload = parts[65];
return msg;

```

result " 'outerLeftRearTirePressure': {'value': '227'"

What I need is a msg.payload containing the 227 element as a number but I am having big difficulty, help would be appreciated.

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [3 January 2022 14:51 UTC](https://discourse.nodered.org/t/array-split-trouble/56041/2 "2022-01-03T14:51:38Z")

</div>

It would be helpful it you displayed some of the initial array so we can see what it is made up of.

---

<div class="post-metadata">

### Author: ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)
#### Post date: [3 January 2022 15:06 UTC](https://discourse.nodered.org/t/array-split-trouble/56041/3 "2022-01-03T15:06:55Z")

</div>

Here's an snippit hope it helps, I tried splice and stuff but what ever I do I end up with "'227'" I cannot seem to get ride of the " " from " ' 277 ' "

': '01-03-2022 06:01:38'}, 'outerLeftRearTirePressure': {'value': '227', 'status': 'CURRENT', 'timestamp': '01-03-2022 06:01:38'}, 'outerRightRea rTireStatus': {'value': 'Normal', 'status': 'CURRENT', 'timestamp': '01-03-2022 06:01:38'}, 'outerRightRearTirePressure': {'value': '227', 'status': 'CURRENT', 'timestamp': '01-03-2022 06:01:38'},

---

<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: [3 January 2022 15:24 UTC](https://discourse.nodered.org/t/array-split-trouble/56041/4 "2022-01-03T15:24:03Z")

</div>

Please feed the message into a debug node and show us what it looks like.

---

<div class="post-metadata">

### Author: ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)
#### Post date: [3 January 2022 15:32 UTC](https://discourse.nodered.org/t/array-split-trouble/56041/5 "2022-01-03T15:32:33Z")

</div>

```auto
msg : Object

object

_msgid: "1b4536be4afe45a7"

payload: "{'vehiclestatus': {'vin': 'xxxxxxxxxxxxxxxxxxxxxxxx', 'lockStatus': {'value': 'LOCKED', 'status': 'CURRENT', 'timestamp': '01-03-2022 06:01:38'}, 'alarm': {'value': 'SET', 'status': 'CURRENT', 'timestamp': '01-03-2022 06:01:38'}, 'PrmtAlarmEvent': {'value': 'Null', 'status': 'CURRENT', 'timestamp': '01-03-2022 06:01:38'}, 'odometer': {'value': 25242.0, 'status': 'CURRENT', 'timestamp': '01-03-2022 06:01:38'}, 'fuel': {'fuelLevel': 55.543656, 'distanceToEmpty': 361.2, 'status': 'CURRENT', 'timestamp': '01-03-2022 06:01:38'}, 'gps': {'latitude': '53.1744467', 'longitude': '-1.1900167', 'gpsState': 'UNSHIFTED', 'status': 'LAST_KNOWN', 'timestamp': '01-01-2022 18:11:34'}, 'remoteStart': {'remoteStartDuration': 0, 'remoteStartTime': 0, 'status': 'CURRENT', 'timestamp': '01-03-2022 06:01:38'}, 'remoteStartStatus': {'value': 0, 'status': 'CURRENT', 'timestamp': '01-03-2022 06:01:38'}, 'battery': {'batteryHealth': {'value': 'STATUS_GOOD', 'timestamp': '12-18-2021 16:22:03'}, 'batteryStatusActual': {'..."

topic: ""

```

Admin Edit: added triple backticks around data to stop forum from messing with format.

---

<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: [3 January 2022 15:40 UTC](https://discourse.nodered.org/t/array-split-trouble/56041/6 "2022-01-03T15:40:43Z")

</div>

That is nearly JSON. If it were then you could feed it into a JSON node and your troubles would be over. Unfortunately it has single quotes in the string instead of double. Where is that coming from? Ideally the source should be fixed to make it valid. Otherwise you could convert all single quotes to double.

---

<div class="post-metadata">

### Author: ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)
#### Post date: [3 January 2022 15:51 UTC](https://discourse.nodered.org/t/array-split-trouble/56041/7 "2022-01-03T15:51:38Z")

</div>

Its a python sketch which connects my car and gets data, according to the sketch the result is supposed to be in Jason format, I'm using the exec node to get the result into node-red.

---

<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: [3 January 2022 15:54 UTC](https://discourse.nodered.org/t/array-split-trouble/56041/8 "2022-01-03T15:54:51Z")

</div>

Well it isn't JSON as JSON must use double quotes. Preferably change the sketch accordingly. If you can't do that then you can feed it through a Change node configured with  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/a/8a6f133e16dafc54190d79281c08d1921ef067a7.png)

Feed that into a debug node to check it looks right, then through a JSON node and into a debug node to see what you get. If you don't know what to do with the javascript object then there is a great page in the docs that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<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: [17 January 2022 15:54 UTC](https://discourse.nodered.org/t/array-split-trouble/56041/9 "2022-01-17T15:54:58Z")

</div>

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