How to combine values in one object from different objects JSON [{key1:val1},{key2:val2}] =>{key1:val1, key2:val2 }(Function)

Hello community, I need your help. This is what the incoming data looks like.

Снимок экрана 2021-08-18 в 20.14.06

How to combine values in one object
Снимок экрана 2021-08-18 в 20.14.21

My WorkFlow: { "name": "Need help", "nodes": [ { "parameters": {}, "name": "Start", "type": "n8n-nodes-base.start", "typeVersion": 1, "position": [ 250, 300 ] }, { "parameters": { "functionCode": "return [\n {\n json:[\n {\n id: 1,\n name: \"Jim\"\n }, \n {\n id: 2,\n name: \"Stefan\"\n },\n {\n id: 3,\n name: \"Hans\"\n }\n ]\n }\n];" }, "name": "Mock Data", "type": "n8n-nodes-base.function", "position": [ 500, 210 ], "typeVersion": 1 }, { "parameters": { "functionCode": "return items[0].json.map(item => { \n return {\n json: item,\n }\n})\n" }, "name": "Create JSON-items", "type": "n8n-nodes-base.function", "position": [ 740, 210 ], "typeVersion": 1 }, { "parameters": { "functionCode": "return [\n {\n json:\n {\n 1: \"Jim\",\n 2: \"Stefan\",\n 3: \"Hans\"\n }\n }\n];" }, "name": "NEED DATA in 1 Object", "type": "n8n-nodes-base.function", "position": [ 900, 340 ], "typeVersion": 1 } ], "connections": { "Mock Data": { "main": [ [ { "node": "Create JSON-items", "type": "main", "index": 0 }, { "node": "NEED DATA in 1 Object", "type": "main", "index": 0 } ] ] }, "Start": { "main": [ [ { "node": "Mock Data", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": {}, "id": "82" }

return [].concat(
  items.reduce((acc, cur) => {
	acc.json[cur.json.id] = cur.json.name;
	return acc;
  }, { json: {} })
);
2 Likes