Convert csv string to array

I feel this should be possible using basic nodes but I'm failing to acheive a result

I've got and rgb triple coming in via MQTT as a csv string e.g

255,255,0

but I need to change it to an array to feed the WS2801 node

String method split() with separator comma split(",") makes array
Or with split node
image

That just seems to give me 3 separate string messages

Right, but can be fixed by using a join node after the split node, with below config.

a-1

1 Like

Simon, Does this JSONata expression in a change node do what you want?

payload.$split(",").$number()

(not sure if you need an array of numbers, or just leave them as strings...)

Yes it does but I trying to see if a core node would do it - I felt the csv node would do it on its own but it doesn't

Well, of course the change and function nodes are core... but I get your point.

So here is an alternative solution -- use the template node to build an array "string" and output as "parsed JSON"

... which only works if you are guaranteed to have input strings of comma-separated numbers.
In practice, you would probably want to add some kind of error checking.

1 Like

yep _ I had that one but I think its pretty much the same as using JSONata

Actually - your template looks different to mine #strange

These are the setting I needed to get an array output

Forgive me for digging up this topic.
I have a csv file

TF1,1
France 2,2
France 3,3
France 5,5
M6,6
...

I would like to convert it to an array:

msg.payload: array[200]
   0: "TF1","1"
   1: "France 2","2"
   2: "France 3","3"
   3: "France 5","5"
   4: "M6","6"
   ...

I tried whith split - join and template node whitout succes.
Can you help me
Thanks

Have you tried the CSV node?