Overview
In this tutorial, you will learn how to create mock data in n8n to test AI automation workflows without relying on live APIs or production data. We will explore multiple practical methods to generate realistic sample data, including using external mock data generators, leveraging AI-powered tools like ChatGPT, and creating custom mock data inside n8n itself. These techniques will help you build, debug, and optimize your workflows more efficiently while avoiding risks associated with live data.
Why Mock Data is Essential for AI Automation Workflows
Before diving into the methods, it’s important to understand why mocking data is a crucial practice when building AI automation workflows:
- Test Without Live APIs: Avoid repeated calls to external APIs, saving time and reducing costs.
- Simulate Real-World Scenarios: Real data may not always be readily available or diverse enough to cover edge cases.
- Introduce Randomness: Randomized data better mimics real user behavior and uncovers potential issues.
- Predictable Development: Small, controlled data sets produce predictable results, aiding debugging.
- Protect Production Data: Prevent accidental overwrites or corruptions in your live environment during early development.
Mock data also helps you master error handling in n8n by allowing you to simulate failure scenarios safely. For more on this, check out our guide on Master Error Handling in n8n.
Method 1: Using an External Mock Data Generator (Mockaroo)
Mockaroo is a versatile online tool to generate large volumes of realistic mock data with customizable schemas.
Steps to Generate and Use Data from Mockaroo
Create a Schema:
- Define fields like
ID,First Name,Last Name,Email,Gender,Company, etc. - Customize field types using Mockaroo’s extensive list (e.g., email, IP address, stock symbols).
- Set options like the percentage of blank values for certain fields to simulate missing data.
- Define fields like
Add or Remove Fields:
- You can add new fields or delete unnecessary ones.
- Use formulas to create calculated fields (e.g., profit = sale price - purchase price).
Use AI to Generate Fields:
- Click on “Generate Fields Using AI” to automatically create fields for scenarios like flight logs or stock trades.
- Specify time ranges and numeric ranges to control randomness.
Generate Data:
- Click “Generate Data” to produce your sample dataset.
- Preview the data before downloading it.
Download Data:
- Export the data as JSON or CSV files.
Import Data into n8n:
- Open your n8n workflow.
- Add a
Manual Triggernode. - Click the node’s output “Edit” icon to open the editable mode.
- Paste the JSON mock data directly into the node’s output.
- Save and pin the data for further use in your workflow.
Example: Filtering Stock Trades Using an IF Node
After loading mock stock transaction data:
- Add an
IFnode. - Set the condition to check if the
transactionTypeequalsbuy. - Execute the node to split records into
buyandsellbranches. - Build your automation logic based on these branches.
This approach integrates well with other nodes such as the Gmail node for sending notifications. For details on configuring email workflows, refer to the n8n Gmail node documentation.
Method 2: Generating Mock Data Using AI (ChatGPT)
You can leverage AI language models like ChatGPT to generate custom mock data tailored for your workflow needs.
How to Use ChatGPT for Mock Data Generation
- Prepare a Prompt:
Example prompt:
I'm working on an n8n automation workflow simulating user signups for email automation.
Please generate about 1000 random mock user signup records with at least six fields,
including email ID. Include some blank email IDs to simulate missing data.
Provide the data both in CSV and JSON formats.
Request Data in CSV Format:
- Ask ChatGPT to provide data in CSV format for easy import into tools like Google Sheets.
Request Data in JSON Format:
- Ask ChatGPT to provide the same data as a JSON list, suitable for direct use in n8n nodes.
Download and Review the Data:
- Save the generated CSV and JSON files.
- Open and verify the data structure and content.
Import JSON Data into n8n:
- Open the
WebhookorManual Triggernode in your workflow. - Use the “Edit Output” feature to replace the default output with the JSON mock data.
- Save and pin the data to simulate incoming requests.
- Open the
Troubleshooting JSON Format Errors
- Error: Unexpected non-whitespace character after JSON at position ...
- Cause: JSON data is not properly formatted as a list of objects.
- Fix: Ask ChatGPT to return the data wrapped in a JSON array (list of items).
Example correction prompt:
Please format the JSON data as a list of items (JSON array).
Once fixed, the mock data can be used seamlessly in your workflow to simulate user signups or other events.
Method 3: Creating Custom Mock Data Inside n8n
For quick tests or simple data structures, you can create mock data directly within n8n using the Set (formerly Edit Field Set) or Code nodes.
Using the Set Node for Single Records
- Add a
Setnode to your workflow. - Manually add fields and values (e.g., order number, customer name, email).
- You can nest JSON objects to represent complex data (e.g., an order with multiple products).
- This method is ideal for small-scale or early-stage testing with a few records.
Using the Code Node for Programmatic Data Generation
- Add a
Codenode. - Use JavaScript to generate arrays of mock data dynamically.
- Return data in the format n8n expects:
return [
{
json: {
orderNumber: '12345',
customerName: 'John Doe',
email: 'john.doe@example.com',
products: [
{ name: 'Product A', quantity: 2 },
{ name: 'Product B', quantity: 1 }
]
}
},
// Add more records as needed
];
- You can write loops and logic to create large datasets with custom rules.
For more on handling complex data and binary files within n8n, see our lesson on File Management & Binary Data in n8n.
Method 4: Using the Customer Data Store Node (Limited Use)
n8n offers a Customer Data Store node that contains a small set of sample data.
- Add the
Customer Data Storenode. - Use the
Get All Peopleaction to retrieve sample records. - Note: The node has a limited dataset (e.g., 5 records), so it’s not suited for large-scale testing.
- Useful for quick demos or learning purposes.
Putting It All Together: Example Workflow Using Mock Data
- Start with a
Manual TriggerorWebhooknode. - Load mock data into the node output using the "Edit Output" feature.
- Use an
IFnode to filter or branch your data based on field values. - Add additional nodes for processing, e.g., Google Sheets, Slack, Notion, Airtable.
- Test the workflow with your mock data to ensure all branches and nodes behave as expected.
For example, you might integrate a Google Forms Webhook in n8n to simulate form submissions as part of your testing workflow.
Common Mistakes and Troubleshooting Tips
Improper JSON Formatting:
- Always ensure your JSON mock data is a properly formatted array of objects.
- Use JSON validators or ask AI tools to reformat if errors occur.
Data Field Mismatch:
- Make sure the mock data fields match exactly with what your workflow nodes expect.
- Missing or extra fields can cause errors or unexpected behavior.
Large Data Volume Overload:
- Avoid loading too many records at once in early testing to keep execution fast.
- Gradually increase dataset size once your workflow logic is stable.
Not Pinning Edited Data:
- After pasting mock data into a node’s output, always pin it to freeze the data for consistent testing.
Ignoring Missing Data Scenarios:
- Include blank or null values in fields like email to test how your workflow handles incomplete data.
Useful n8n Documentation Links
Quick Reference Cheat Sheet
| Method | Use Case | Pros | Cons |
|---|---|---|---|
| Mockaroo | Large realistic datasets | Easy UI, customizable, AI fields | Requires export/import step |
| ChatGPT | Custom, large datasets in CSV/JSON | AI-generated, flexible prompts | May need JSON formatting fixes |
| Set Node | Simple single-record testing | Quick, no external tools | Not suited for bulk data |
| Code Node | Custom logic and large dataset generation | Fully programmable, flexible | Requires JavaScript knowledge |
| Customer Data Store Node | Small predefined sample data | Built-in, no setup needed | Very limited dataset |
By mastering these methods, you can confidently create and manage mock data in n8n, enabling faster, safer, and more effective AI automation workflow development. As shown in the video above, combining external tools with n8n’s native features offers powerful options to simulate real-world data scenarios without the risk or overhead of live environments.