How to merge and aggregate to not output broken empty json

Describe the problem/error/question

Merging and Aggregating results into broken JSON

I am getting a binary file from Notion Trigger and when using Notion Get page content, the binary file and Notion database properties are overwritten in the flow and only the Notion Get Page content is passed on. So, I have used a Merge but this means one object doesn’t have all the items as the other. And I also had to use a merge because I couldn’t access the second JSON item properly without it.

In the code node, I’m turning the Notion Page content into a specific format (e.g. Notion to Pinterest description) and passing it along.

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.) 

Share the output returned by the last node

Aggregate Output:
“id”: “0291155e-64ba-4d48-8590-6f58d669ac19”,
“name”: “7 ways to use AI”,
“property_publishing”: “AI”,
“property_type”: “type”,
“property_media”: [”
“property_topic”: “AI”,
“property_sub_topic”: null,
“property_post_link”: null
“pinterestPin”: “This is a test \nThis is 21 2 @pinterest\nThis is line 4\n• sdasadsd\n\nHi\n1. dfsjlkfjdsfl\n2. fdslkjlkdsjfldsf\n\n👋\nsklajdsakjhd\nhttps://www.pinterest\n\n#pinterest\nd2323d\n\nIntroduction\nArtificial Intvdfnce (AI) has revolutionized numerous industries with its ability to perform tasks that traditionally required human intelligence. In recent years, AI has also made significant advancements in the creative field. From assisting with content creation to enhancing the overall creative process, AI”
Merge Output:


Information on your n8n setup

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

Hey @pooria,

Do you happen to have a small worklfow that reproduces this? Having the output of the Merge node could be useful so we can test it.

It looks like as your merge node is just appending though it could be worth using the merge to actually merge the items together so you have the 1 output rather than the 2.

@Jon hit a character limit (I added “40k characters” but limit is “30k” or sth), so posting the workflow on a Google Docs:

Hey @pooria,

I have tried running that workflow but it fails on teh URL to Binary Media node, Are you able to mock the data response so we have a workflow that reproduces this problem?

@Jon it’s just a simple image (so just binary data).


Updated the N8N workflow here with the correct URL to get binary data:

Hey @pooria,

So what is happening is you are using Append in the merge which is creating 2 items as you add the items from input 1 and input 2 together. You are then aggragating the data of 2 items once which has data and one that doesn’t this is just creating an array of data items as there are no matching fields.

In the JSON post you are then using $ but that value doesn’t exist exist as it is $[0].name. The quickest way to fix this would be to change the merge node to use Combine by Postion so that it adds the data from input 2 to the data from input 1 giving you the one item that you can then reference.

From here you can drop the aggregate node and change the JSON you are using to the below and you will be good to go.


"title": $ ,      
"description": $json.pinterestPin,       
"board_id": "918452986446117775",       
"media_source": {         
"source_type": "image_url",         
"url": $json.property_media[0]         


That worked beautifully.

Thx Jon

1 Like

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