HELP Convert array of objects to array of arrays using change node

Hi,
I am new to Node-RED and I really could use some help. I am trying to read two CSV files containing tables with values and sum up the entries of the two tables. I am now stuck in the step where the CSV node gives me an array of objects which I want to convert to an array of arrays. Apparently, I can do that with a change node or with a function but I am stuck.
nodered

thanks in advance!

Hey, could you visualize how you want it to look like?

looks like you need to set your csv node separator to ; semicolon.
Then in a change node you could use JSONata to a sum the column, something like
$sum($$.payload.col1)

thanks for the quick reply, it is supposed to be an array of arrays, sthg like [[1,4], [2,5], [3,6]]

humm, how can I do that?

Maybe look in the csv node settings, where it says separator.

e.g.

[{"id":"eeb9211a8f426608","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"1;4\n2;5\n3;6","output":"str","x":240,"y":3660,"wires":[["1ea8d77edebaa5e4"]]},{"id":"e6a0e1f18fc8f86f","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":3660,"wires":[["eeb9211a8f426608"]]},{"id":"1ea8d77edebaa5e4","type":"csv","z":"452103ea51141731","name":"","sep":";","hdrin":"","hdrout":"none","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":310,"y":3700,"wires":[["5626199d0b983e3e","0e936280b366a6f0"]]},{"id":"5626199d0b983e3e","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.[$.*]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":3700,"wires":[["71b6e778f177aa3d"]]},{"id":"0e936280b366a6f0","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum($$.payload.col1)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":3740,"wires":[["15e9acb625811019"]]},{"id":"71b6e778f177aa3d","type":"debug","z":"452103ea51141731","name":"debug 107","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":3700,"wires":[]},{"id":"15e9acb625811019","type":"debug","z":"452103ea51141731","name":"debug 108","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":3740,"wires":[]}]

I managed to change it and it helped, thanks!
PS: I keep seeing the thing you attached as an example everywhere, I know they are supposed to help but I have no idea what they are :sweat_smile:

They are example flows. If you had read the doc's you would know what they are and how to use them Importing and Exporting Flows : Node-RED . I suggest you spend some time reading and watching the videos, it will save you a lot of time and enable you to make better use of node-red and the in built tools.

1 Like

thanks a lot! I'll definitely look into that

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