# Write JSON to file

**URL:** <https://community.n8n.io/t/write-json-to-file/160>\
**Category:** Questions\
**Tags:** move-binary-data\
**Created:** [October 11, 2019, 1:55pm UTC](https://community.n8n.io/t/write-json-to-file/160 "2019-10-11T13:55:10Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mikey](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@Mikey](https://community.n8n.io/u/Mikey)\
**Post date:** [October 11, 2019, 1:55pm UTC](https://community.n8n.io/t/write-json-to-file/160/1 "2019-10-11T13:55:10Z")

</div>

How do I write JSON data to file? I tried using the “write binary file” node, but can’t get that to work with JSON, it only seems to work with the xls file.

Thanks again so much!

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [October 11, 2019, 3:15pm UTC](https://community.n8n.io/t/write-json-to-file/160/2 "2019-10-11T15:15:43Z")

</div>

Uh yes, you are right! The problem is that the “Write Binary File” expects binary data. The JSON data is, however, JSON 😉 There should really be a node that allows moving data around between both of them.

For now, it can be done with a Function-Node. At least till a proper one is in place. Pasted an example of how you can do that to the end of the message. The first node you can remove, it is only to create the example data. The second node named “Make Binary” is the important one with the custom code which makes the data binary and writes it to the correct location.

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [October 11, 2019, 3:19pm UTC](https://community.n8n.io/t/write-json-to-file/160/3 "2019-10-11T15:19:40Z")

</div>

Uh sorry always forget that people maybe do not know what they are supposed to do with the JSON I post.

You can simply copy the JSON above, click once in the n8n window and then paste (CTRL + v). It will then create the nodes.

---

<div class="post-metadata">

**Author:** ![Mikey](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@Mikey](https://community.n8n.io/u/Mikey)\
**Post date:** [October 11, 2019, 4:26pm UTC](https://community.n8n.io/t/write-json-to-file/160/4 "2019-10-11T16:26:13Z")

</div>

Thanks again Jan! U da man!

I posted a workflow with your example:

[EXAMPLE: Write JSON to Disk (Binary)](https://n8n.io/workflows/101)

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [October 11, 2019, 8:26pm UTC](https://community.n8n.io/t/write-json-to-file/160/5 "2019-10-11T20:26:46Z")

</div>

Great, thanks a lot!

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [October 31, 2019, 9:54pm UTC](https://community.n8n.io/t/write-json-to-file/160/6 "2019-10-31T21:54:13Z")

</div>

In the latest version of n8n@0.31.0 there is now a special node called “Move Binary Data”:

> **[n8n](https://n8n.io/integrations/n8n-nodes-base.moveBinaryData)**
>
> n8n is an extendable workflow automation tool which enables you to connect anything to everything via its open, fair-code model.

It allows moving data between binary and JSON.

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [November 1, 2019, 10:42am UTC](https://community.n8n.io/t/write-json-to-file/160/7 "2019-11-01T10:42:52Z")

</div>

Please use 0.31.1 it contains some important changes.

---

<div class="post-metadata">

**Author:** ![syadnom](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/syadnom/32/30830_2.png) [@syadnom](https://community.n8n.io/u/syadnom)\
**Post date:** [December 17, 2023, 4:14am UTC](https://community.n8n.io/t/write-json-to-file/160/8 "2023-12-17T04:14:22Z")

</div>

resurecting instead of opening new.

I’m having a similar need here and though I’m on a much newer version and ‘move binary data’ is there, I’m not getting desired results

I have an API call that returns 8600 records. When I pull that in and run it through ‘move binary data’ and select all, I can see that it’s processing each entry and writing it to the file I specify. Overwriting. So I end up with 1 correct record in the file.

If I select ‘append’, then it doesn’t clear that file on the next run and malforms the output and grows it.

Really need 1 of 2 things to happen here.

1. overrite file but append records within execution run
2. truncate/delete file.

I can’t find a way to do either.

The ultimate goal here is to simply pull the API contents and cache them in a file. Unfortunately the vendor doesn’t let me filter this data out in the API call, so I pull the entire data set out on each execution. I want to just run this as a separate scheduled task and write that to a file, then operate on that cached file.

API JSON → json\>binary → write binary file. This is where I’m either overwriting records and end up with 1, or I’m appending and it malforms it and grows it forever.

Ideas?

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [December 27, 2023, 11:44am UTC](https://community.n8n.io/t/write-json-to-file/160/9 "2023-12-27T11:44:49Z")

</div>

Hi @syadnom, this is the expected behaviour in n8n. Most n8n nodes will perform their action for every single incoming item.

If you’d like to have a single file with with the content of multiple items you’d first need to aggregate your data into a single item. For example like so:

This will leave you with a single file containing multiple items:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/7/f/7f4c22beb88595c00044a9a1dcc654282676eb45.png)

Hope this helps!

Going forward, perhaps you want to open a new thread instead of re-opening old ones? n8n has changed a lot in the past four years, so mixing old and new content often leads to confusion.

Thanks so much!

---

<div class="post-metadata">

**Author:** ![syadnom](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/syadnom/32/30830_2.png) [@syadnom](https://community.n8n.io/u/syadnom)\
**Post date:** [December 27, 2023, 6:58pm UTC](https://community.n8n.io/t/write-json-to-file/160/10 "2023-12-27T18:58:56Z")

</div>

> [@syadnom](#):
>
> I have an API call that returns 8600 records. When I pull that in and run it through ‘move binary data’ and select all, I can see that it’s processing each entry and writing it to the file I specify. Overwriting. So I end up with 1 correct record in the file.

I don’t have that ‘aggregate’ node, v1.20.0 which is current docker from the n8nio repo…

---

<div class="post-metadata">

**Author:** ![syadnom](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/syadnom/32/30830_2.png) [@syadnom](https://community.n8n.io/u/syadnom)\
**Post date:** [December 27, 2023, 7:14pm UTC](https://community.n8n.io/t/write-json-to-file/160/11 "2023-12-27T19:14:32Z")

</div>

found that aggregate was added in 1.22, updated and it’s there. This works.

---

<div class="post-metadata">

**Author:** ![ihortom](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ihortom/32/11473_2.png) [@ihortom](https://community.n8n.io/u/ihortom)\
**Post date:** [December 27, 2023, 7:59pm UTC](https://community.n8n.io/t/write-json-to-file/160/12 "2023-12-27T19:59:54Z")

</div>

@syadnom , in the previous version of n8n you would use Item Lists with “Summarize” option. For example,

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [January 3, 2024, 8:00pm UTC](https://community.n8n.io/t/write-json-to-file/160/13 "2024-01-03T20:00:01Z")

</div>

Closed on January 3, 2024, 8:00pm UTC

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