How to merge 3 HTTP responses into 1 JSON by comparing a common header and eliminate duplicate headers?

Not able to merge the http responses in 1 Json, comparing a common header and eliminate duplicate headers. When we are using merge node for merging, the responses are getting merged one after another

What is the error message (if any)?

Please share your workflow

for example if
Http 1 response is

[
{
a=1,
b=2,
c=3
}
]

Http2 response

[
{
a=1,
y=4,
i=7,
o=8
}
]

Expected output is :

[
{
a=1,
b=2,
c=3,
y=4,
i=7,
o=8
}
]

the output we are receiving is incorrect in the workflow:

[
{
a=1,
b=2,
c=3
},
{
a=1,
y=4,
i=7,
o=8
}
]

Please help me get the expected output

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

Hey @Meghna_Rajeev,

Welcome to the community :cake:

Are you sure that response is correct? The JSON is invalid which will make it very tricky to work with. Can you share your workflow as well so we can take a look?

sure I can share the workflow.
Please, Can you guide me how can i share the workflow here?

Hey @Meghna_Rajeev,

It normally tells you in the template we provide, You will need to select the nodes in your workflow and paste it into a reply here.

Please also don’t forget to check that the json response you have shared is correct as it isn’t valid JSON and that will be a problem.

hello Jon,
Please find below the flow :

Hey @Meghna_Rajeev,

In that example you can just use Merge By Position and it will sort it out, It looks like the JSON in the code node is different from the example you shared earlier as well.

1 Like

Ok I understood.
Please consider the below example :
JSON 1: [
{
β€œa”:β€œ1”,
β€œb”:β€œβ€,
β€œc”:β€œ3”,
},
{
β€œa”:β€œ3”,
β€œb”:β€œ5”,
β€œc”:β€œ10”,
}
]

JSON 2:
[
{
β€œa”:β€œ1”,
β€œy”:β€œ8”,
β€œi”:β€œ7”,
β€œo”:β€œ9”,
},
{
β€œa”:β€œ0”,
β€œy”:β€œ5”,
β€œi”:β€œ4”,
β€œo”:β€œ8”,
}
]

where β€œa” and β€œa” will have same values always, and we need to compare jsons with the help of header β€œa”

the expected output is
[
{
β€œa”: β€œ1”,
β€œb”: β€œβ€,
β€œc”: β€œ3”,
β€œy”: β€œ8”,
β€œi”: β€œ7”,
β€œo”: β€œ9”
},
{
β€œa”: β€œ1”,
β€œb”: β€œβ€,
β€œc”: β€œ3”,
β€œy”: β€œ8”,
β€œi”: β€œ7”,
β€œo”: β€œ9”
}
]

please help me how can I get this output, as we are getting only one object not 2 object.
Please refer the below worlflow.

Hey @Meghna_Rajeev,

Looking at the example that is working as expected as your second A item in the Code 1 node has a different value so the match isn’t there.

Hello, It is resolved I got the output I was looking for.
Thankyou so much for your help, I Totally appreciate.

1 Like