通过 Webhook 验证 JSON 字符串
中级
这是一个Building Blocks领域的自动化工作流,包含 6 个节点。主要使用 Code, Webhook, RespondToWebhook 等节点。 通过Webhook验证JSON字符串
前置要求
- •HTTP Webhook 端点(n8n 会自动生成)
分类
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "6GzSyLakqBN2hYIe",
"meta": {
"instanceId": "1777696fb9fddfee653e70940936c2b1e28ba1f1bde53b7182fbd6eb01988706"
},
"name": "通过 Webhook 验证 JSON 字符串",
"tags": [],
"nodes": [
{
"id": "72785a1d-32f6-4f0d-a412-5327c059ddd3",
"name": "Webhook:接收 JSON 字符串",
"type": "n8n-nodes-base.webhook",
"position": [
-680,
-140
],
"webhookId": "2604aa77-b575-4c3f-b1df-feab9c775603",
"parameters": {
"path": "validate-json-string",
"options": {},
"httpMethod": "POST",
"responseMode": "responseNode"
},
"typeVersion": 2
},
{
"id": "940b04da-3f16-434d-8181-9452dd3ba007",
"name": "使用结果响应 Webhook",
"type": "n8n-nodes-base.respondToWebhook",
"position": [
100,
-140
],
"parameters": {
"options": {},
"respondWith": "allIncomingItems"
},
"typeVersion": 1.2
},
{
"id": "4546866f-9376-47cf-ac19-caf0eb197cca",
"name": "代码:验证 JSON 字符串",
"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": "注意:Webhook 输入",
"type": "n8n-nodes-base.stickyNote",
"position": [
-760,
-360
],
"parameters": {
"width": 280,
"height": 380,
"content": "## Webhook 输入"
},
"typeVersion": 1
},
{
"id": "f3f93504-93b2-40e9-93e6-45366a681ac0",
"name": "注意:JSON 验证逻辑",
"type": "n8n-nodes-base.stickyNote",
"position": [
-420,
-320
],
"parameters": {
"color": 2,
"width": 350,
"height": 360,
"content": "## JSON 验证逻辑"
},
"typeVersion": 1
},
{
"id": "e8632087-424b-40b4-a894-301885137f49",
"name": "注意:Webhook 响应",
"type": "n8n-nodes-base.stickyNote",
"position": [
0,
-320
],
"parameters": {
"color": 3,
"width": 350,
"height": 360,
"content": "## Webhook 响应"
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"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
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 构建模块
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
通过Webhooks使用ScreenshotMachine API按需生成网站截图
通过Webhooks使用ScreenshotMachine API按需生成网站截图
If
Code
Webhook
+3
12 节点ist00dent
构建模块
通过 Webhook 的内容摘要生成器 (ApyHub)
通过 Webhook 的内容摘要生成器 (ApyHub)
Webhook
Http Request
Respond To Webhook
+1
8 节点ist00dent
构建模块
通过 TimeZoneDB API 集成转换时区
使用TimeZoneDB API集成转换时区
Webhook
Http Request
Respond To Webhook
+1
6 节点ist00dent
构建模块
通过 Webhook 使用 ExchangeRate.host 进行货币转换
使用 ExchangeRate.host 通过 Webhook 进行货币转换
Webhook
Http Request
Respond To Webhook
+1
6 节点ist00dent
构建模块
通过Webhook进行IP地理位置查询
通过Webhook使用IP-API.com查询IP地理位置详情
Webhook
Http Request
Respond To Webhook
+1
6 节点ist00dent
构建模块
通过 Webhook 查询公共假日
通过 Webhook 使用 Nager.Date API 查询公共假日
Webhook
Http Request
Respond To Webhook
+1
6 节点ist00dent
构建模块
工作流信息
难度等级
中级
节点数量6
分类1
节点类型4
作者
ist00dent
@ist00dentI’m a dedicated automation engineer passionate about no-code and low-code solutions. I design and implement robust n8n workflows—integrating APIs, databases, and messaging—to eliminate manual tasks and accelerate delivery. Leveraging Python and C#, I build scalable, adaptable automations that empower teams to focus on high-value work.
外部链接
在 n8n.io 查看 →
分享此工作流