SET node and json list,iterate over each element

Hi
I have the following output from a node

[
{
"count": 24,
"entities": [
{
"data": {
"EMAIL": "mail",},
"typeId": null,
"domain": "domain",
"createdAt": "2022-09-20T19:46:53.174Z",
"updatedAt": "2022-09-20T19:46:53.174Z"
},
{
"data": {
"EMAIL": "mail",
},
"typeId": null,
"domain": "domain",
"createdAt": "2022-09-20T17:03:38.714Z",
"updatedAt": "2022-09-20T17:03:38.714Z"
},

I want to filter this data with a set node, however I can’t find a way to get all items in entities
n8n is suggesting a expression like this
{{$json[“entities”][0][“data”][“EMAIL”]}}

but it should be something like this
{{$json[“entities”][index][“data”][“EMAIL”]}}

I know it is a noob question, but indeed I am a noob with N8N
Thanks

Hi @Luca_Pierabella, the output you have shared doesn’t seem to be valid JSON I am afraid. Assuming the full structure looks like the example structure in in my workflow, you could use the Item Lists node to split up your entities field. You could then use the Set node as usual.

Here’s an example workflow showing the idea:

Hope this helps! Let me know if you have any questions on this.

thanks, it works
I made some extra step but i’m now stuck with the IF node
How do I check the existance of a element of a list in another list?

Hi, i almost finished my flow
I still have some issue
The function node has two input and it is executed two times, why?
I also set in the settings “Execute Once”, but the execution data is still 2

Hi @Luca_Pierabella

There is 2 lines coming into the function node, so for each it will execute once.
The execute once only applies to the items coming into it. So for example if you have 10 items it will not run 10 times but just the one time.
Now it does this 2 times as there is 2 lines coming in it, so triggering it twice for only 1 item.

1 Like

Sure, it make sense.
My function is checking the existence of the items from a ListA inside ListB
So how should I achieve this?

Sorry, I do not understand.
Do you have an example of Input and expected output?

sure and thanks a lot for your help
here the output of “Get Newsletter Table”

[
	{
		"mail": "[email protected]",
		"createdAt": "2022-09-20T19:46:53.174Z"
	},
	{
		"mail": "[email protected]",
		"createdAt": "2022-09-20T19:46:53.174Z"
	}
]

here the outoput of “Item Lists”

[
	{
		"data": {
			"EMAIL": "[email protected]"
			},
		"id": 154933,
		"typeId": null,
		"domain": "https://www.domain.com/",
		"createdAt": "2022-09-21T16:29:30.158Z",
		"updatedAt": "2022-09-21T16:29:30.158Z",
		"submissionTypeName": null,
		"submissionTypeId": null,
		"dataFileFields": [
		]
	},
	{
			"data": {
			"EMAIL": "[email protected]"
			},
			"id": 154375,
			"typeId": null,
			"domain": "https://www.domain.com/",
			"createdAt": "2022-09-20T19:46:53.174Z",
			"updatedAt": "2022-09-20T19:46:53.174Z",
			"submissionTypeName": null,
			"submissionTypeId": null,
			"dataFileFields": [
			]
	}
]

the expected result should be

[
	{
		"data": {
			"EMAIL": "[email protected]"
			},
		"id": 154933,
		"typeId": null,
		"domain": "https://www.domain.com/",
		"createdAt": "2022-09-21T16:29:30.158Z",
		"updatedAt": "2022-09-21T16:29:30.158Z",
		"submissionTypeName": null,
		"submissionTypeId": null,
		"dataFileFields": [
		]
	}
]

Hey @Luca_Pierabella,

Have you tried the merge node? That can check items that exist or don’t exist from 2 inputs, Using the data you shared it would be something like the workflow below.

2 Likes

well turns out i was using 0.144.0 of n8n so the merge node was completely different
Now it works perfectly
thanks for your help … I managed to do it with the Merge node as you suggested

2 Likes