JSON String Validator via Webhook
This n8n template provides a simple yet powerful utility for validating if a given string input is a valid JSON format. You can use this to pre-validate data received from external sources, ensure data integrity before further processing, or provide immediate feedback to users submitting JSON strings. --- ## How it works - Webhook: This node acts as the entry point for the workflow, listening for incoming POST requests. It expects a JSON body with a single property: - jsonString: The string that you want to validate as JSON. - Code (JSON Validator): This node contains custom JavaScript code that attempts to parse the jsonString provided in the webhook body. - If the jsonString can be successfully parsed, it means it's valid JSON, and the node returns an item with valid: true. - If parsing fails, it catches the error and returns an item with valid: false and the specific error message. - This logic is applied to each item passed through the node, ensuring all inputs are validated. - Respond to Webhook: This node sends the validation result (either valid: true or valid: false with an error message) back to the service that initiated the webhook request. --- ## Who is it for? ### This workflow is ideal for: - Developers & Integrators: Pre-validate JSON payloads from external systems (APIs, webhooks) before processing them in your workflows, preventing errors. - Data Engineers: Ensure the integrity of JSON data before storing it in databases or data lakes. - API Builders: Offer a dedicated endpoint for clients to test their JSON strings for validity. - Customer Support Teams: Quickly check user-provided JSON configurations for errors. - Anyone handling JSON data: A quick and easy way to programmatically check JSON string correctness without writing custom code in every application. --- ## Data Structure When you trigger the webhook, send a POST request with a JSON body structured as follows: ``` { "jsonString": {"name": "n8n", "type": "workflow"} } ``` Example of an invalid JSON string: ``` { "jsonString": {"name": "n8n"} // Missing quotes around name } ``` The workflow will return a JSON response indicating validity: For a valid JSON string: ``` { "valid": true } ``` For an invalid JSON string: ``` { "valid": false, "error": "Unexpected token n, {'name': 'n8n'} is not valid JSON" } ``` --- ## Setup Instructions - Import Workflow: - In your n8n editor, click Import from JSON and paste the provided workflow JSON. - Configure Webhook Path: - Double-click the Webhook node. - In the Path field, set a unique and descriptive path (e.g., /validate-json). - Activate Workflow: - Save and activate the workflow. --- ## Tips This JSON validator workflow is a solid starting point. Consider these enhancements: - Enhanced Error Feedback: - Upgrade: Add a Set node after the Code node to format the error message into a more user-friendly string before responding. - Leverage: Make it easier for the caller to understand the issue. - Logging Invalid Inputs: - Upgrade: After the Code node, add an IF node to check if valid is false. If so, branch to a node that logs the invalid jsonString and error to a Google Sheet, database, or a logging service. - Leverage: Track common invalid inputs for debugging or improvement. - Transforming Valid JSON: - Upgrade: If the JSON is valid, you could add another Function node to parse the jsonString and then operate on the parsed JSON data directly within the workflow. - Leverage: Use this validator as the first step in a larger workflow that processes JSON data. - Asynchronous Validation: - Upgrade: For very large JSON strings or high-volume requests, consider using a separate queueing mechanism (e.g., RabbitMQ, SQS) and an asynchronous response pattern. - Leverage: Prevent webhook timeouts and improve system responsiveness.
This n8n template provides a simple yet powerful utility for validating if a given string input is a valid JSON format. You can use this to pre-validate data received from external sources, ensure data integrity before further processing, or provide immediate feedback to users submitting JSON strings.
How it works
-
Webhook: This node acts as the entry point for the workflow, listening for incoming POST requests. It expects a JSON body with a single property:
- jsonString: The string that you want to validate as JSON.
-
Code (JSON Validator): This node contains custom JavaScript code that attempts to parse the jsonString provided in the webhook body.
- If the jsonString can be successfully parsed, it means it's valid JSON, and the node returns an item with valid: true.
- If parsing fails, it catches the error and returns an item with valid: false and the specific error message.
- This logic is applied to each item passed through the node, ensuring all inputs are validated.
-
Respond to Webhook: This node sends the validation result (either valid: true or valid: false with an error message) back to the service that initiated the webhook request.
Who is it for?
This workflow is ideal for:
- Developers & Integrators: Pre-validate JSON payloads from external systems (APIs, webhooks) before processing them in your workflows, preventing errors.
- Data Engineers: Ensure the integrity of JSON data before storing it in databases or data lakes.
- API Builders: Offer a dedicated endpoint for clients to test their JSON strings for validity.
- Customer Support Teams: Quickly check user-provided JSON configurations for errors.
- Anyone handling JSON data: A quick and easy way to programmatically check JSON string correctness without writing custom code in every application.
Data Structure
When you trigger the webhook, send a POST request with a JSON body structured as follows:
{ "jsonString": {"name": "n8n", "type": "workflow"}
}
Example of an invalid JSON string:
{ "jsonString": {"name": "n8n"} // Missing quotes around name
}
The workflow will return a JSON response indicating validity:
For a valid JSON string:
{ "valid": true
}
For an invalid JSON string:
{ "valid": false, "error": "Unexpected token n, {'name': 'n8n'} is not valid JSON"
}
Setup Instructions
-
Import Workflow:
- In your n8n editor, click Import from JSON and paste the provided workflow JSON.
-
Configure Webhook Path:
- Double-click the Webhook node.
- In the Path field, set a unique and descriptive path (e.g., /validate-json).
-
Activate Workflow:
- Save and activate the workflow.
Tips
This JSON validator workflow is a solid starting point. Consider these enhancements:
-
Enhanced Error Feedback:
- Upgrade: Add a Set node after the Code node to format the error message into a more user-friendly string before responding.
- Leverage: Make it easier for the caller to understand the issue.
-
Logging Invalid Inputs:
- Upgrade: After the Code node, add an IF node to check if valid is false. If so, branch to a node that logs the invalid jsonString and error to a Google Sheet, database, or a logging service.
- Leverage: Track common invalid inputs for debugging or improvement.
-
Transforming Valid JSON:
- Upgrade: If the JSON is valid, you could add another Function node to parse the jsonString and then operate on the parsed JSON data directly within the workflow.
- Leverage: Use this validator as the first step in a larger workflow that processes JSON data.
-
Asynchronous Validation:
- Upgrade: For very large JSON strings or high-volume requests, consider using a separate queueing mechanism (e.g., RabbitMQ, SQS) and an asynchronous response pattern.
- Leverage: Prevent webhook timeouts and improve system responsiveness.
New buyers can create an account from the cart to unlock a controlled $10 first-purchase credit on eligible orders of $25+.
Secure checkout powered by Stripe
Support
How to import this workflow into n8n
- 1Purchase or download the workflow to get the n8n workflow JSON file.
- 2In your n8n instance, open Workflows and choose "Import from File" (or paste the JSON with Ctrl+V on the canvas).
- 3Open each node marked with a credential warning and connect your own accounts and API keys.
- 4Run the workflow once manually to verify the data flow, then toggle it to Active.
Related Development & IT workflows
- Create daily historical AI videos with Gemini, fal.ai, Telegram and YouTube$14.99
- Advanced multi-agent AI personal assistant with 250+ task capabilities (WhatsApp + GPT)$2.99
- Send Organized Security CVE Digests from NVD with AI-Polished Summaries to Gmail$4.99
- Learn n8n basics in 3 easy steps ✨$14.99
- Automated multi-platform sales agent with RAG, CRM & payment processing$2.99
- Version Control n8n Workflows in GitLab with Custom and Organization$14.99
More from ist00dent
Need this deployed? We'll set it up for you.
Our automation experts deploy this workflow in your stack, connect your accounts, and verify it works — or build a custom solution from scratch.