Merge two tables, with concat comma list?

I have a table of data in JSON format, it looks like this. A unique row for every UID, but the Tag field may be repeated.

Tag UID
TagA UID1
TagA UID2
TagB UID3
TagB UID4

The end result I am trying to achieve should look like this, a single row for each Tag, with each associated UID concatenated as a comma list.

Tag UID
TagA UID1, UID2
TagB UID3, UID4

I think I need to merge all the tags together somehow, but I don’t know how to do that properly. It seems that I should use a Merge or Compare node, but what I’ve tried so far didn’t work.

Does anyone have an idea what I should try to do next?

Information on your n8n setup

  • n8n version: 1.28.0
  • Database: SQLite
  • n8n EXECUTIONS_PROCESS setting: Default
  • Running n8n via: npm
  • Operating system: Windows 11

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:

Bumping this. I am sure this must be possible, I’m just thinking of it wrong so far. Anyone have suggestions?

hello @protechtedd

Here are two options for how you can achieve that:

Hey @barn4k , thanks for your reply, although I tested this and it is not quite working as expected. I’ve prepared a dataset pasted below, if you’ll give this a try I think you’ll see what I mean. You’ll need to save the JSON code block into a Tags.json, then edit the “Read File” node to point to it, so the flow can read and split the data into the exact format I am working with on my side. This way we’ll be on the same page.

The workflow:

The JSON data:

[
	{
		"Tag": "TagName1",
		"UID": "leKFEGX8haEgIADx"
	},
	{
		"Tag": "TagName1",
		"UID": "UXz1YNk2et0oEiL3"
	},
	{
		"Tag": "TagName1",
		"UID": "FVAAPnctmoVUZvLq"
	},
	{
		"Tag": "TagName1",
		"UID": "NAlq2RoaA3ZhyUnd"
	},
	{
		"Tag": "TagName1",
		"UID": "Kml8HyqRU2lzTt9c"
	},
	{
		"Tag": "TagName2",
		"UID": "XIUIPXTWOBqW9Gpa"
	},
	{
		"Tag": "TagName2",
		"UID": "I78HQzQC0wEOXfts"
	},
	{
		"Tag": "TagName2",
		"UID": "s3a1rjBGF2c9AAGH"
	},
	{
		"Tag": "TagName2",
		"UID": "E5p0noWVVshhlpSQ"
	},
	{
		"Tag": "TagName2",
		"UID": "IO0phegDbtdmxiff"
	}
]

Hi @protechtedd,
I believe using just the Concat Node will solve your issue. It handles combining the UIDs per Tag and the Edit node can be used to rename the field if needed. You could also use the rename keys field.

3 Likes

That worked! I think the combination of “Comma and Space” plus the “Fields to split by” is what worked here. Thanks a bunch for the help! And welcome to the forums

Glad to help!

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