Extracting data from arrays and concatanating

Good afternoon again,
I have yet to fully grasp the message object and wondered if someone would be good enough to offer some help after a couple of hours struggling.
I inject an sql query and get an array(7) back. I would like to join the 7 parts into a single string to then pass on to another function. I would like the format to be like this ["10","11","12","13","14","15","16"]
I have attached a screenshot of the debug message I get on injecting the SQL

Kind Regards
Andrew

I would say there is an issue with your sql query and the format it returns. It would be best to get this correct first. Your object seem to be missing property names. So maybe you should look it to this as you should be able to do all this in the sql query and get the return in the format you wish.

Saying that you can use JSONata to correct the returned array, but this would not be my way to go. So for informational purposes this expression in a change node should work to return a JSON (string) converting all numbers to strings.

[{"id":"3735d7573e2021e1","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"\":1},{\"\":2}]","payloadType":"json","x":420,"y":100,"wires":[["37fee9af24c282d1"]]},{"id":"37fee9af24c282d1","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$string($$.payload.*.$string($))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":100,"wires":[["bfb6ba0b79001503"]]},{"id":"bfb6ba0b79001503","type":"debug","z":"d1395164b4eec73e","name":"debug 2561","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":100,"wires":[]}]

Hi E1cid
Many thanks for the suggestion I will modify my SQL query to attach a name to each part of the array and retry

Cheers
Andrew

Your other issue (which may be fixed on the SQL end) is that each element in the array contains an object when in fact it is a single value (number) - this speaks to something being returned incorrectly and is probably why you are having problems.

Craig

Good Morning Craig
Many thanks for your help
I am in the process of altering my sql.
My main issue is that on discovering Nodered I was blown away with its ability to allow me to carry out quite complex tasks without very much coding.
I might be able to write complex sql stored procedures but still struggle with the basics of the msg.payload.

Regards
Andrew

1 Like

Yep it is overwhelming to start with - spend some time and try and read as many of the forum posts as possilbe and it will start to seep in with some osmosis.

Craig

1 Like

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