I am trying to save the output of a Notion > Database Page > Get Many node as a JSON file on my local computer (running community n8n). But I am having trouble with the JSON formatting to make it work with future steps.
You can see above that the last output is in a different format. It’s like the entire JSON got stored inside a dictionary or object or something (still learning JSON structures).
What can I do to write and then read that Notion output JSON data in the exact same format as I first got it (as a table)?
@EmeraldHerald That did work, however is it possible to change this code to go somewhere before the “Write JSON” node?
The problem with doing it during the “read file” phase is that the original file is still being written as an invalid JSON. This causes external apps to be unable to use the file.
Additionally, the node “Write JSON” is iterating and overwriting the file as individual records, instead of a single file with all records as an array. If I activate the node’s option “Append”, it does add them all, but the output JSON is no longer valid. Perhaps this can be fixed with code?
Update: I found this code snippet to try injecting before converting the JSON to binary then writing to file. It seems to format the JSON as valid, but the code still needs modifying because it wraps everything inside “data” and changes the formatting compared to the original (from Notion). Could we use this at all, or should I discard it for another solution?
Okay, I spent some time over the weekend scouring for solutions. I solved one half of the problem, but the other half still isn’t working. I am open to changing anything / everything about this if you think it needs reworking. Am I fundamentally thinking about this correctly?
A quick recap of my goal: To write the output JSON from a Notion node into a valid JSON file, then be able to read that same file into a JSON/Table that n8n can compare via Comparison node with both Notion output and JSON file. Essentially, comparing a previous run to the current run to detect changes.
I updated the workflow from my original example. The “Write to JSON” row successfully converts and writes the Notion data to a JSON file. The “Read from JSON” row reads the saved file, but stores the output as a different format than expected, especially when compared to the original Notion format.
The strange thing to me is that when I copy the text from the Output > JSON tab from each, and paste them into a “text difference” tool, absolutely nothing is different between them. So this tells me that n8n is just parsing the data differently than I’m expecting for some reason; Do I need some node after “Binary to JSON” before sending to the Comparison node?
Workflow:
Screenshots below from the output of the final Comparison node.
Just following up here that I have been using a system that works well for my needs. In case anyone comes here looking for help with this, here is an example set of nodes. This primarily works for Notion nodes, but could help with other types too. The ? nodes are a custom addon called “@n-octo-n/n8n-nodes-json-database”