Google Drive File Content to Single Key-Value Dictionary Aggregation - n8n Workflow

A crucial n8n workflow template that loads content from multiple Google Drive documents within a specified folder and aggregates them into a single, clean JSON dictionary using an n8n Code node. Ideal for RAG or AI inputs.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Data Preprocessing Specialists: Users needing to consolidate raw text data from multiple sources into a single payload for large language models (LLMs).

  • Automation Architects: Developers looking for reusable n8n templates for complex data restructuring tasks.

  • Content Managers: Anyone required to batch-process content stored in Google Docs within a specific folder.

  • n8n Users: Individuals seeking advanced examples of using the n8n Code node for data aggregation.

Overview

Processing large amounts of documentation often requires reading content from multiple files and presenting it in a standardized format. This specialized n8n workflow addresses the challenge of managing multi-item outputs from file operations. It uses the Google Drive n8n node to identify all files in a folder, downloads the content using the Google Docs n8n node, and critically, uses a Set n8n node followed by a custom Code n8n node to combine all these separate items into one master dictionary. This single-item output, where the key is the filename and the value is the clean content, is extremely valuable for downstream AI processing, search indexing, or complex data transformations. This structure is a powerful example of advanced n8n automation logic, suitable for use as a component in larger n8n templates.

How it Works

This n8n workflow is initiated by the 'When Executed by Another Workflow' n8n trigger, making it an excellent component for parent n8n templates or for manual testing.


  1. File Identification: The initial n8n trigger passes control to the Google Drive n8n node, which lists all files found within a configured Google Drive folder (initially set to the root, but customizable).

  2. Content Retrieval: The workflow iterates through the list of files. For each file, the Google Docs n8n node downloads the document content using its unique ID.

  3. Item Mapping: The Set n8n node, named 'Mapping,' performs a temporary transformation. It dynamically creates an item where the key is the original file name (pulled from the initial Google Drive n8n node output) and the value is the retrieved document content.

  4. Data Aggregation (Code): The final 'Code' n8n node receives all these individual mapped items. This custom JavaScript code iterates through every input item, extracting the single key-value pair and adding it to a master dictionary (aggregatedDict). It also includes string cleaning logic to compress excessive newlines, ensuring clean output. The result of this complex n8n node is a single item containing the complete aggregated dictionary, ready for the next step in your larger n8n workflow.

Installation Guide

To deploy this robust n8n workflow template:


  1. Import: Copy the provided JSON data and paste it directly into your n8n canvas using the 'New' -> 'Import from JSON' option.

  2. Credentials: You must configure credentials for the Google Drive n8n node and the Google Docs n8n node. Click on these nodes, select 'Create New Credential,' and follow the OAuth 2 setup process for Google authentication.

  3. Configuration: Update the 'Get files from folder' Google Drive n8n node to specify the exact folderId you wish to process, rather than the default 'Root folder.'

  4. Adaptation: If you are processing files other than Google Docs (e.g., PDFs or plain text), you must replace the 'Download Google Docs' n8n node with the appropriate n8n node (like the Google Drive or HTTP Request n8n node) that can retrieve the file's binary data and convert it to text.

Node Details


  • When Executed by Another Workflow (n8n trigger): Acts as the starting point, enabling this logic to be reusable across various n8n templates.

  • Get files from folder (Google Drive n8n node): Lists files within the target Google Drive folder. Key configuration involves setting the specific folderId.

  • Download Google Docs (Google Docs n8n node): Retrieves the full content of each identified document. It uses a dynamic expression ={{ $json.id }} to fetch the document ID passed from the previous n8n node.

  • Mapping (Set n8n node): Restructures the data stream. The key is set using the expression ={{ $('Get files from folder').item.json.name }} (the file name) and the value is the document content (={{ $json.content }}). This prepares the data for final aggregation by the next n8n node.

  • Code (n8n Code node): This is the core logic engine. It iterates through all input items, combines their key-value pairs into a single JSON object, and cleans up line breaks. This custom n8n node ensures the final output is a single, consolidated dictionary.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by

Hobbyist n8n automation maker, I build custom automations for people.

Featured*