Combining JSON into a single structure

Describe the problem/error/question

I’m trying to implement this function to combine 5 JSON structures… sorry bit of a noob with JavaScript. Am i doing something wrong?

function combineIntoLookAlikeDomains(json1, json2, json3, json4, json5) {
return {
look_alike_domains: {
…json1,
…json2,
…json3,
…json4,
…json5
}
};
}

const json1 = $(‘MAIN’).first().json;
const json2 = $(‘CVE’).first().json;
const json3 = $(‘CERTIFICATE’).first().json;
const json4 = $(‘IPADDRESS’).first().json;
const json5 = $(‘HOST2’).first().json;

const combinedJson = combineIntoLookAlikeDomains(json1, json2, json3, json4, json5);

What is the error message (if any)?

Error: Code doesn't return items properly
    at JavaScriptSandbox.validateRunCodeAllItems (/usr/lib/node_modules/n8n/node_modules/n8n-nodes-base/nodes/Code/Sandbox.ts:85:10)
    at JavaScriptSandbox.runCodeAllItems (/usr/lib/node_modules/n8n/node_modules/n8n-nodes-base/nodes/Code/JavaScriptSandbox.ts:75:15)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Object.execute (/usr/lib/node_modules/n8n/node_modules/n8n-nodes-base/nodes/Code/Code.node.ts:130:13)
    at Workflow.runNode (/usr/lib/node_modules/n8n/node_modules/n8n-workflow/src/Workflow.ts:1253:8)
    at /usr/lib/node_modules/n8n/node_modules/n8n-core/src/WorkflowExecute.ts:1024:29

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • **n8n version: 1.0
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):npm
  • **Operating system:ubuntu 22

Hi @alykhan, welcome to the community!

Looks like all that’s missing is a final return statement. Try adding return combinedJson; below your existing code :slight_smile:

In a workflow this looks like so:

Result (this is of course random dummy data, just to illustrate the idea):

Hope this helps!

3 Likes

Perfect thank you so much!

2 Likes

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