Convert Multiple items with unique keys to a single item (not an array)

Hi n8n’ers,

I have an API that returns unique key value pairs, where the key names are unique.

But n8n considers this 92 different items, which I get.

What I need to do, is combine the 92 items into a single item that is not an array.

The key names are unique so that’s not a problem.

Sample Source:

{
“Cable | Status_id”: 7873359009605508
},
{
“Cable | Status Info_id”: 2243859475392388
},
{
“Cable | Spare_id”: 6747459102762884
}

Output I am hoping for:

{
“Cable | Status_id”: 7873359009605508,
“Cable | Status Info_id”: 2243859475392388,
“Cable | Spare_id”: 6747459102762884,
}

I’ve played with a lot of options, and I know I’m on the edge of this, but it’s hard to find a good resource to understand all the variations of manipulating the structure of json in the context of n8n items (without getting lost in pure JS).

Thanks so much for your help on this show stopper for me!

Hope it helps:

const reduced = items.reduce((acc, cur) => {
  const [[k, v]] = Object.entries(cur.json);
  acc[k] = v;
  return acc;
}, {});

return [{ json: reduced }];
1 Like

Perfect answer! Worked Great, definitely add this to the snippets docs!

This is a perfect example of why I constantly find myself enjoying the n8n ecosystem.

Thanks Ivov!