Help required for data format conversion

Hi friends,
I need help for data format conversion in node red.
i have read three data point from PLC using Siemens S7comm node.
data recieved is in array.
i have converted it in to json using json node.
v have convert below given format.
["58.00","0.0","0.00"]

i want to convert this format in to below mentioned format
{"Level":"58.00","Pressure":"0.0","Flow":"0.00"}

Many ways to do this, here is a quick step-by-step little flow, perhaps you can get some ideas from this example?

[{"id":"724e6c52.22c504","type":"inject","z":"e3827ab.e3e0688","name":"","topic":"","payload":"[\"58.00\",\"0.0\",\"0.00\"]","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":480,"wires":[["97ddafb8.d5c1f"]]},{"id":"2f00f571.446faa","type":"function","z":"e3827ab.e3e0688","name":"","func":"var out = '{\"Level\":\"'+msg.payload[0]+'\",\"Pressure\":\"'+msg.payload[1]+'\",\"Flow\":\"'+msg.payload[2]+'\"}';\nvar newMsg = {payload:out};\nreturn newMsg;\n","outputs":1,"noerr":0,"x":570,"y":480,"wires":[["a3cd5a1.04ccea8"]]},{"id":"ff1f9002.54cc6","type":"debug","z":"e3827ab.e3e0688","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":900,"y":480,"wires":[]},{"id":"a3cd5a1.04ccea8","type":"json","z":"e3827ab.e3e0688","name":"","property":"payload","action":"","pretty":false,"x":730,"y":480,"wires":[["ff1f9002.54cc6"]]},{"id":"97ddafb8.d5c1f","type":"json","z":"e3827ab.e3e0688","name":"","property":"payload","action":"obj","pretty":false,"x":430,"y":480,"wires":[["2f00f571.446faa"]]}]

Easily done with a change node and JSONata or with a function node.

Example (untested) JSONata:

{
    "Level": payload[0],
    "Pressure": payload[1],
    "Flow": payload[2]
}

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