AutomationFlowsGeneral › JSON String Validator via Webhook

JSON String Validator via Webhook

Byist00dent @ist00dent on n8n.io

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…

Webhook trigger★★★★☆ complexity6 nodes
General Trigger: Webhook Nodes: 6 Complexity: ★★★★☆ Added:

This workflow corresponds to n8n.io template #4704 — we link there as the canonical source.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "6GzSyLakqBN2hYIe",
  "name": "JSON String Validator via Webhook",
  "tags": [],
  "nodes": [
    {
      "id": "72785a1d-32f6-4f0d-a412-5327c059ddd3",
      "name": "Webhook: Receive JSON String",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -680,
        -140
      ],
      "parameters": {
        "path": "validate-json-string",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "940b04da-3f16-434d-8181-9452dd3ba007",
      "name": "Respond to Webhook with Result",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        100,
        -140
      ],
      "parameters": {
        "options": {},
        "respondWith": "allIncomingItems"
      },
      "typeVersion": 1.2
    },
    {
      "id": "4546866f-9376-47cf-ac19-caf0eb197cca",
      "name": "Code: Validate JSON String",
      "type": "n8n-nodes-base.code",
      "position": [
        -300,
        -140
      ],
      "parameters": {
        "jsCode": "// This node validates if the 'jsonString' in the webhook body is valid JSON.\n// It returns 'valid: true' or 'valid: false' along with an error message if invalid.\n\nconst results = [];\n\nfor (const item of $input.all()) {\n  try {\n    // Attempt to parse the jsonString from the webhook body\n    // Ensure 'jsonString' exists before attempting to parse\n    if (item.json.body && typeof item.json.body.jsonString === 'string') {\n      JSON.parse(item.json.body.jsonString);\n      results.push({ json: { valid: true } });\n    } else {\n      // Handle cases where jsonString is missing or not a string\n      results.push({ json: { valid: false, error: \"Input 'jsonString' is missing or not a string.\" } });\n    }\n  } catch (e) {\n    // If parsing fails, push the error message\n    results.push({ json: { valid: false, error: e.message } });\n  }\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "52ea0a9b-863d-4d09-b96b-ab707571738b",
      "name": "Note: Webhook Input",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -760,
        -360
      ],
      "parameters": {
        "width": 280,
        "height": 380,
        "content": "## Webhook Input\n\nThis node listens for incoming POST requests. It expects a JSON body containing a single property: `jsonString` (the string you wish to validate as JSON)."
      },
      "typeVersion": 1
    },
    {
      "id": "f3f93504-93b2-40e9-93e6-45366a681ac0",
      "name": "Note: JSON Validation Logic",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -420,
        -320
      ],
      "parameters": {
        "color": 2,
        "width": 350,
        "height": 360,
        "content": "## JSON Validation Logic\n\nThis node contains custom JavaScript code to parse the `jsonString` from the webhook input. It returns `valid: true` if successful, or `valid: false` with an `error` message if parsing fails."
      },
      "typeVersion": 1
    },
    {
      "id": "e8632087-424b-40b4-a894-301885137f49",
      "name": "Note: Webhook Response",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -320
      ],
      "parameters": {
        "color": 3,
        "width": 350,
        "height": 360,
        "content": "## Webhook Response\n\nThis node sends the validation result (whether the `jsonString` was valid JSON or not, including an error if applicable) back to the system that triggered the webhook."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "ecec4bf1-c92e-485f-9f8f-fc98441310eb",
  "connections": {
    "Code: Validate JSON String": {
      "main": [
        [
          {
            "node": "Respond to Webhook with Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook: Receive JSON String": {
      "main": [
        [
          {
            "node": "Code: Validate JSON String",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

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…

Source: https://n8n.io/workflows/4704/ — original creator credit. Request a take-down →

More General workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

General

A clean, extensible REST-style API routing template for n8n webhooks with up to 3 path levels. Serves API routes via Webhooks with path variables Normalizes incoming requests into "global" REQUEST and

General

PUQ Docker NextCloud deploy. Uses respondToWebhook, stickyNote, httpRequest, ssh. Webhook trigger; 44 nodes.

HTTP Request, Ssh
General

puq-docker-immich-deploy. Uses respondToWebhook, ssh, stickyNote. Webhook trigger; 35 nodes.

Ssh
General

Analyze_email_headers_for_IPs_and_spoofing__3. Uses stickyNote, respondToWebhook, itemLists, httpRequest. Webhook trigger; 35 nodes.

Item Lists, HTTP Request
General

puq-docker-n8n-deploy. Uses respondToWebhook, ssh, stickyNote. Webhook trigger; 34 nodes.

Ssh