Transform JSON field to string array


I am working with the node "node-red-contrib-modbustcp" and I am trying to create a server. I know that the server is working because I am connected to it by using a modbus master. The problem is that I need to transform the field payload that you can see remarked in red in the image attached into a string array and I don't know how to get it.

I want only the numbers that are remarked, not the name. You know, something like: "(62296,1743,18368,5015,61975,24713,35923,16468)"


Can you post the debug output in text ?
Or even better, make a mockup flow that only produces the output.

Come to think of it, you can use the csv node to make a comma separated string.

Are you sure you want as a string with embedded values, not as an array for example?
Whichever, first have a look at the article on working with messages in the docs, which will show you how to access the components. Then if you do really want it as a string as you have shown then you can use the string interpolation technique to build the string in a function node, something like this

msg.payload = `(${msg.payload.BATTERIA},${msg.payload.somethingelse}, ...)`

The Modbus Server says this: "msg.payload must be an array of numbers or strings with values between 0:65535". I understand that I need an array but that its composed by strings.

So, what do I put in the function node exactly?

So you want an array of values, not a string containing the values. So in the function node you will need something like

msg.payload = [msg.payload.BATTERIA, msg.payload.somethingelse, ...]
return msg

The square brackets tell it to construct an array containing the values.
There are other ways rather than using a function node, but for learning a bit about javascript that is a good way.

ok, thank you! That is exactly what I am looking for.


Simpler still, use Object.values(msg.payload).

If that is all you want to do in the function, I think you can do that with JSONata as well.

I assume that @carlosglez needs them in some specific order, likely not the same as Object.values() will return.

I think that it returns them in the order found but I might be wrong.