Array Split trouble

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 ...

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.

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

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'},

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

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.

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.

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.

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

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://nodered.org/docs/user-guide/messages

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