[Solved] Join several object messages to one object message?

I have several messages of type {msg: Object object value1: "v1" value2: "v2" value3: "v3" value4: "v4" _msgid: "xxxx"} and I would like to combine them into one array msg [0]: value1: " v1 "value2:" v2 "value3:" v3 "value4:" v4 "_msgid:" xxxx "
msg [1]: value1: "v1a" value2: "v2a" value3: "v3a" value4: "v4a" _msgid: "xxxxa"
....
msg [n]: value1: "v1n" value2: "v2n" value3: "v3n" value4: "v4n" _msgid: "xxxxn".
Unfortunately, I can't get it through the node "Join". Please give me a hint how I can do it

Well neither of the examples you give are valid json so it's going to be hard to guess exactly what you mean....

Flow

[{"id":"5d1aab30.471e04","type":"debug","z":"d0071538.bb23f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":590,"y":3580,"wires":[]},{"id":"dc7a513f.41bf3","type":"join","z":"d0071538.bb23f8","name":"","mode":"custom","build":"merged","property":"","propertyType":"full","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":470,"y":3720,"wires":[["5d1aab30.471e04","2fed6b5d.7e8984"]]},{"id":"78eee376.7b1bac","type":"debug","z":"d0071538.bb23f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":810,"y":3720,"wires":[]},{"id":"2fed6b5d.7e8984","type":"ui_template","z":"d0071538.bb23f8","group":"5e69aaae.44d674","name":"Data-table","order":1,"width":13,"height":6,"format":"<style>\n th {\n text-decoration: underline;\n }\n .numeric {\n text-align: right;\n padding-right: 15px;\n }\n</style>\n\n\n<table cellpadding=\"1\" border=\"1\" id=\"table1\" class=\"table-hover\" style=\"width: 100%;\">\n <thead>\n <tr>\n <th>No</th> \n <th>Header1</th> \n <th>Header2</th>\n <th>Header3</th>\n <th>header4</th>\n </tr>\n </thead>\n <tbody>\n <tr ng-repeat=\"row in msg.payload\">\n <td style=\"width: 3%\" class=\"numeric\" >{{row.value1}}</td>\n <td>{{row.value2}}</td>\n <td style=\"width: 10%\">{{row.value3}}</td>\n <td style=\"width: 10%\">{{row.value4}}</td>\n <td style=\"width: 10%\">{{row.value5}}\n </tr>\n </tbody>\n</table>\n\n<script>\n(function($scope) {\n var array = [];\nvar table = document.querySelector(\"table tbody\");\nvar rows = table.children;\nfor (var i = 0; i < rows.length; i++) {\n\tvar fields = rows[i].children;\n var rowArray = [];\n for (var j = 0; j < fields.length; j++){\n rowArray.push(fields[j].innerHTML);\n }\n array.push(rowArray);\n} \n $scope.sendRow = function(obj) {\n$scope.send({ \"payload\": array });\n }; \n})(scope);\n</script>\n\n<!--script>\n(function($scope) {\n $scope.sendRow = function(obj) {\n $scope.send({ \"payload\": obj });\n $scope.send({ \"payload\": (document.getElementById(\"table1\").rows[1].innerHTML) });\n };\n})(scope);\n</script-->","storeOutMessages":false,"fwdInMessages":false,"templateScope":"local","x":650,"y":3720,"wires":[["78eee376.7b1bac"]]},{"id":"28b78355.776b4c","type":"inject","z":"d0071538.bb23f8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":3700,"wires":[["6e3a2df0.68b844"]]},{"id":"b23e0b63.005068","type":"inject","z":"d0071538.bb23f8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":3760,"wires":[["b6d4913d.26c54"]]},{"id":"a19df461.82a7e8","type":"function","z":"d0071538.bb23f8","name":"dummyarray expected","func":"var myArray =[\n{ \"value1\": \"v1a\", \"value2\": \"v2a\", \"value3\": \"v3a\", \"value4\": \"v4a\", \"value5\": \"v5a\"},\n{ \"value1\": \"v1b\", \"value2\": \"v2b\", \"value3\": \"v3b\", \"value4\": \"v4b\", \"value5\": \"v5b\"},\n];\nmsg.payload = myArray;\nreturn msg;","outputs":1,"noerr":0,"x":740,"y":3880,"wires":[["2fed6b5d.7e8984"]]},{"id":"6e3a2df0.68b844","type":"function","z":"d0071538.bb23f8","name":"dummyarray 1","func":"msg={\nvalue1: \"v1a\",\nvalue2: \"v2a\",\nvalue3: \"v3a\",\nvalue4: \"v4a\",\n};\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":3700,"wires":[["dc7a513f.41bf3","cca46d0b.6b672"]]},{"id":"b6d4913d.26c54","type":"function","z":"d0071538.bb23f8","name":"dummyarray 2","func":"msg={\nvalue1: \"v1b\",\nvalue2: \"v2b\",\nvalue3: \"v3b\",\nvalue4: \"v4b\",\n};\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":3760,"wires":[["dc7a513f.41bf3","b44d7d3.85c908"]]},{"id":"cca46d0b.6b672","type":"debug","z":"d0071538.bb23f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":330,"y":3640,"wires":[]},{"id":"b44d7d3.85c908","type":"debug","z":"d0071538.bb23f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":330,"y":3840,"wires":[]},{"id":"276a9a5e.584586","type":"comment","z":"d0071538.bb23f8","name":"expected outcome  ","info":"","x":590,"y":3820,"wires":[]},{"id":"553a3f8a.57dc3","type":"inject","z":"d0071538.bb23f8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":560,"y":3880,"wires":[["a19df461.82a7e8"]]},{"id":"5e69aaae.44d674","type":"ui_group","z":"","name":"Torrrenty na RPi","tab":"d285a0a4.78899","disp":true,"width":"13","collapse":false},{"id":"d285a0a4.78899","type":"ui_tab","z":"","name":"Home","icon":"home","order":1}]

Try it like this:

[{"id":"ed8c1e32.c79e28","type":"debug","z":"402f1c98.9dab44","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":746,"y":216,"wires":[]},{"id":"b67fdfde.581e3","type":"join","z":"402f1c98.9dab44","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":602,"y":216,"wires":[["ed8c1e32.c79e28"]]},{"id":"1d26a4f2.ef830b","type":"inject","z":"402f1c98.9dab44","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":132,"y":192,"wires":[["7114cd0e.b5e264"]]},{"id":"a6ccc9d1.76d2e","type":"inject","z":"402f1c98.9dab44","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":132,"y":252,"wires":[["e7e55a26.963b8"]]},{"id":"7114cd0e.b5e264","type":"function","z":"402f1c98.9dab44","name":"dummyarray 1","func":"msg.payload={\nvalue1: \"v1a\",\nvalue2: \"v2a\",\nvalue3: \"v3a\",\nvalue4: \"v4a\",\n};\nreturn msg;","outputs":1,"noerr":0,"x":312,"y":192,"wires":[["479fdca0.35c75c"]]},{"id":"e7e55a26.963b8","type":"function","z":"402f1c98.9dab44","name":"dummyarray 2","func":"msg.payload={\nvalue1: \"v1b\",\nvalue2: \"v2b\",\nvalue3: \"v3b\",\nvalue4: \"v4b\",\n};\nreturn msg;","outputs":1,"noerr":0,"x":312,"y":252,"wires":[["479fdca0.35c75c"]]},{"id":"479fdca0.35c75c","type":"batch","z":"402f1c98.9dab44","name":"","mode":"count","count":"2","overlap":0,"interval":10,"allowEmptySequence":false,"topics":[],"x":482,"y":216,"wires":[["b67fdfde.581e3"]]}]

Note that I have changed both objects to msg.payload (instead of msg), then use the batch node to combine them and the join node to merge them into an array of objects.

Thank you for the hint :). After minor changes I adapted to my needs :slight_smile:

2 Likes