Converting msg.payload array into an object to access its value

Hello everyone!
Greetings of the day! I am currently stuck on a pronlem and need your expert opinion regarding the same. I want to convert a msg.payload which is an array into an object as I want to access a value from that array and set it to a different node. Can you please help me regarding the same. I am attaching the pictures for your reference.
image

I want to access the value in valueread. Any help is highly appreciated!
Thank you

  1. search & replace ' with " in msg.payload[0]
  2. copy msg.payload[0] to msg.payload
  3. pass it through a JSON node

↑ This assumes there is only 1 in element [0] (thats all you show)

PS
Please post data instead of pictures (I would have made you a quick working demo)


TIPS

To copy data from node-red ALWAYS use the "copy value" button that appears when you hover over the property

When pasting data, ALWAYS press the code button </> first on the forum toolbar

Hey, thank you for your quick response. The payload is -

"{'connection': 'open', 'data_status': 'Data recieved from the controller', 'service': '8e', 'status': '00', 'addedstatussize': '00', 'addedstatus': '0000', 'valueread': '1', 'connection_status': 'closed'}"

I have formátted the data like you said but that is in python, once the data is recieved from the controller and displayed in node-red it automatically converts " to '
json= {"connection": "open" , "data_status":"Data recieved from the controller", "service": data[24:25].hex(), "status": data[25:26].hex(), "addedstatussize": data[26:27].hex(), "addedstatus": data[29:30].hex() + data[28:29].hex(), "valueread": str(int.from_bytes(data[32:33], "big"),),"connection_status": "closed" }
print(json) # printing the data that the controller sends

admin edit - format data as instructed in previous post!

Hi, next time you might wanna put the actual text rather than an image in the post.

[{"id":"6941a25e8d7159af","type":"inject","z":"46bc23ae0f413065","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"{'connection': 'open','data status': 'Data recieved from the controller','service': 'Be','status':'00','addedstatussize': '00','addedstatus': '0000','valueread': '1','connection status':'closed'}\"]","payloadType":"json","x":230,"y":240,"wires":[["c65749d5d7994507"]]},{"id":"0b2fab7daa98d303","type":"json","z":"46bc23ae0f413065","name":"","property":"payload","action":"","pretty":false,"x":590,"y":240,"wires":[["dbb99aabc2aac8b5","a0450d3b18150beb"]]},{"id":"c65749d5d7994507","type":"change","z":"46bc23ae0f413065","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"},{"t":"change","p":"payload","pt":"msg","from":"'","fromt":"str","to":"\"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":240,"wires":[["0b2fab7daa98d303"]]},{"id":"dbb99aabc2aac8b5","type":"debug","z":"46bc23ae0f413065","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":280,"wires":[]},{"id":"a0450d3b18150beb","type":"debug","z":"46bc23ae0f413065","name":"valueread","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.valueread","targetType":"msg","statusVal":"","statusType":"auto","x":740,"y":240,"wires":[]}]

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