Join two payloads together

Hello! I know this looks like it has already been asked, but I have reason to believe that my case is quite different, since I don't have an Inject node.

I have two HTML selectors, one returning an array of strings and the other returning an array of image sources (Wikipedia tables stuff). I want to eventually build from these arrays:

  • A JSON array combining the two arrays (each element should be an object with "string" and "image" properties)
  • A CSV file with the two fields as columns.

However, the join node is not working for me, since I have two separate msg.payloads from the two HTML parsers; if I change the output names to each of the latter, they don't put their respective fields into a single object, but it still keeps the messages separated. Anybody know how can I "trick" this?

You need to join manually as a key/object. You also have to add topics to your two incoming payloads, you can add change nodes after the to html nodes to add topics..
here is an example

[{"id":"40490139.b2586","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"string","payload":"[\"string1\",\"string2\"]","payloadType":"json","x":200,"y":3220,"wires":[["55644378.d2d494"]]},{"id":"55644378.d2d494","type":"join","z":"c74669a0.6a34f8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":370,"y":3200,"wires":[["9512251d.ff92"]]},{"id":"9512251d.ff92","type":"function","z":"c74669a0.6a34f8","name":"","func":"let newarray = [];\nfor(i=0; i<msg.payload.string.length; i++){\n    newarray.push({string: msg.payload.string[i], image: msg.payload.image[i]});\n}\nmsg.payload=newarray;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":530,"y":3200,"wires":[["19d1f9f7.86f8ce","9b1fbf91.0a4b38"]]},{"id":"24e8532e.fd99bc","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"image","payload":"[\"link1\",\"link2\"]","payloadType":"json","x":170,"y":3260,"wires":[["55644378.d2d494"]]},{"id":"19d1f9f7.86f8ce","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":3220,"wires":[]},{"id":"9b1fbf91.0a4b38","type":"csv","z":"c74669a0.6a34f8","name":"","sep":",","hdrin":"","hdrout":"all","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":600,"y":3280,"wires":[["19d1f9f7.86f8ce"]]}]

Copy flow json, then press CTRL I in the editor past flow then press import.

Thank you for your answer!
I actually solved it like this:

[{"id":"438d7bbd.346164","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"7afa23c5.9b83bc","type":"http request","z":"438d7bbd.346164","name":"GET","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://en.wikipedia.org/wiki/List_of_presidents_of_the_United_States","tls":"","persist":false,"proxy":"","authType":"","x":270,"y":240,"wires":[["5bd8d206.b2710c"]]},{"id":"c401d0f9.be7bc","type":"inject","z":"438d7bbd.346164","name":"Begin scrape","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":220,"wires":[["7afa23c5.9b83bc","f99c2bbb.4d0728"]]},{"id":"5bd8d206.b2710c","type":"html","z":"438d7bbd.346164","name":"Scrape presidents names","property":"payload","outproperty":"presidents","tag":"table.wikitable b a[title]","ret":"text","as":"single","x":470,"y":240,"wires":[["53c18369.e80b5c"]]},{"id":"d159540a.7ee2a8","type":"file","z":"438d7bbd.346164","name":"Write JSON to file","filename":"presidents.json","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":890,"y":240,"wires":[["38b407d.29a02f8"]]},{"id":"f99c2bbb.4d0728","type":"file","z":"438d7bbd.346164","name":"Delete JSON if exists","filename":"presidents.json","appendNewline":true,"createDir":false,"overwriteFile":"delete","encoding":"none","x":300,"y":160,"wires":[[]]},{"id":"1a598750.0026e9","type":"inject","z":"438d7bbd.346164","name":"Begin CSV","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":620,"wires":[["6331f48c.a27aec","f2f53e06.eace8"]]},{"id":"6331f48c.a27aec","type":"file in","z":"438d7bbd.346164","name":"Load file","filename":"presidents.json","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":340,"y":620,"wires":[["4d634971.4e3048"]]},{"id":"c0b5a245.31e1b","type":"debug","z":"438d7bbd.346164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1090,"y":660,"wires":[]},{"id":"ea4b3720.8e5638","type":"csv","z":"438d7bbd.346164","name":"Parse CSV (debug)","sep":",","hdrin":true,"hdrout":"all","multi":"one","ret":"\\n","temp":"","skip":"0","strings":false,"include_empty_strings":"","include_null_values":"","x":890,"y":660,"wires":[["c0b5a245.31e1b"]]},{"id":"6d5602e.99381fc","type":"debug","z":"438d7bbd.346164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1090,"y":740,"wires":[]},{"id":"53c18369.e80b5c","type":"html","z":"438d7bbd.346164","name":"Scrape portraits","property":"payload","outproperty":"portraits","tag":"table.wikitable a.image img[src]","ret":"attr","as":"single","x":420,"y":300,"wires":[["65c1a878.720a48"]]},{"id":"65c1a878.720a48","type":"function","z":"438d7bbd.346164","name":"Build JSON from msg","func":"let temp = []\n\nfor (let i = 0; i < msg.presidents.length; ++i) {\n    temp[i] = {\n        'president': msg.presidents[i],\n        'image': msg.portraits[i].src\n    }   \n}\n\nmsg.payload = temp;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":720,"y":280,"wires":[["d159540a.7ee2a8"]]},{"id":"38b407d.29a02f8","type":"debug","z":"438d7bbd.346164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1090,"y":240,"wires":[]},{"id":"4d634971.4e3048","type":"json","z":"438d7bbd.346164","name":"Parse JSON","property":"payload","action":"","pretty":false,"x":570,"y":620,"wires":[["e7bc4d1d.f60c4"]]},{"id":"e7bc4d1d.f60c4","type":"function","z":"438d7bbd.346164","name":"JSON 2 CSV","func":"let temp = msg.payload.map(msg => (\n    msg.president + \",\" + msg.image\n    ))\n\nmsg.payload = \"president,image\\n\" + temp.join(\"\\n\")\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":610,"y":740,"wires":[["ea4b3720.8e5638","85a4425b.080ca"]]},{"id":"85a4425b.080ca","type":"file","z":"438d7bbd.346164","name":"Write CSV to file","filename":"presidents.csv","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":860,"y":740,"wires":[["6d5602e.99381fc"]]},{"id":"f2f53e06.eace8","type":"file","z":"438d7bbd.346164","name":"Delete CSV if exists","filename":"presidents.csv","appendNewline":true,"createDir":false,"overwriteFile":"delete","encoding":"none","x":360,"y":560,"wires":[[]]}]

Thank you for taking the time to help! :slight_smile:

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