I would like to handle this json file, extract a number from three arrays and make them a new array. The expectation is:
[ [1,2,3],[4,5,6],[7,8,9]........ ]
I have changed my code and tested in single javascript tester and it works, but there is no output in node-red. I think the problem is, the output of the function must be message but mine is not. I don't know if it's right, so I come here for some help...
var angle_value = { payload: msg.payload["tightening steps"]["2"].graph["angle values"] };
var torque_value = { payload: msg.payload["tightening steps"]["2"].graph["torque values"] };
var time_value = { payload: msg.payload["tightening steps"]["2"].graph["time values"] };
var data = [];
for (i=0;i<angle_value.length;i++){
var b = [];
b[0] = angle_value[i];
b[1] = torque_value[i];
b[2] = time_value[i];
data[i] = b;
}
return data;
Flow below
[
{
"id": "4eed35556f5d6390",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": ""
},
{
"id": "b9eb5c085c98f922",
"type": "file in",
"z": "4eed35556f5d6390",
"name": "curve_sample",
"filename": "C:\\Users\\IHS4SZH\\Desktop\\curve_sample.txt",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "none",
"allProps": false,
"x": 120,
"y": 160,
"wires": [
[
"97bc182de7dec1f2"
]
]
},
{
"id": "97bc182de7dec1f2",
"type": "json",
"z": "4eed35556f5d6390",
"name": "",
"property": "payload",
"action": "obj",
"pretty": false,
"x": 110,
"y": 240,
"wires": [
[
"d7e6efd5cd08d163"
]
]
},
{
"id": "2de8bfab32f6a91e",
"type": "inject",
"z": "4eed35556f5d6390",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 120,
"y": 80,
"wires": [
[
"b9eb5c085c98f922"
]
]
},
{
"id": "547da926858ed6cf",
"type": "debug",
"z": "4eed35556f5d6390",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 110,
"y": 400,
"wires": []
},
{
"id": "d7e6efd5cd08d163",
"type": "function",
"z": "4eed35556f5d6390",
"name": "",
"func": "var angle_value = { payload: msg.payload[\"tightening steps\"][\"2\"].graph[\"angle values\"] };\nvar torque_value = { payload: msg.payload[\"tightening steps\"][\"2\"].graph[\"torque values\"] };\nvar time_value = { payload: msg.payload[\"tightening steps\"][\"2\"].graph[\"time values\"] };\nvar data = [];\nfor (i=0;i<angle_value.length;i++){\n var b = [];\n b[0] = angle_value[i];\n b[1] = torque_value[i];\n b[2] = time_value[i];\n data[i] = b;\n}\nreturn data;\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 120,
"y": 320,
"wires": [
[
"547da926858ed6cf"
]
]
}
]