Combine ticket and article JSON arrays into one object in n8n using Node.js. Use this sample code:
const fuseData = (ticketRec, articleList) => ({ ticket: ticketRec, articles: articleList });
module.exports = fuseData;
Combine ticket and article JSON arrays into one object in n8n using Node.js. Use this sample code:
const fuseData = (ticketRec, articleList) => ({ ticket: ticketRec, articles: articleList });
module.exports = fuseData;
Based on my experience working with JSON in n8n using Node.js, I prefer adding some form of data validation before merging arrays. The sample function provided is a good starting point, but I usually include checks to ensure that the inputs are valid arrays. I have encountered situations where unexpected data formats caused errors in the workflow. In my implementations, I also sometimes perform additional transformations or filtering before merging the data, which can be especially useful when dealing with larger or more complex datasets. This extra layer of verification has saved me a device from potential issues down the line.
Based on my own experience, it’s important to ensure that the input arrays are coming in as expected and that error cases are handled before merging. In my projects, I often include try-catch blocks and validations to check that both JSON structures are valid. Additionally, I sometimes map over the arrays to transform the data so that the merged object has uniform keys, which helps prevent issues when consuming the data later in the workflow. Building defensive code early can significantly reduce runtime errors in n8n workflows.