JSON parsing issue in my contact extraction workflow
I’m building a contact scraper using n8n and getting this error in my subworkflow:
The ‘JSON Output’ in item 0 contains invalid JSON.
The main workflow uses a chatbot agent that calls a subworkflow to extract contacts and save them to Google Sheets. Here’s my main workflow setup:
{
"name": "contactExtractor",
"nodes": [
{
"parameters": {
"name": "contactScraping",
"description": "=Use this to extract contacts when you have search details.\n\nInput format:\n\n[\n {\n \"region\": [\n \"REGION1+HERE\",\n \"REGION2+HERE\"\n ],\n \"industry\": [\n \"INDUSTRY1+HERE\",\n \"INDUSTRY2+HERE\"\n ],\n \"position\": [\n \"POSITION1+HERE\",\n \"POSITION2+HERE\"\n ]\n }\n]",
"workflowId": {
"__rl": true,
"value": "9XkbvWIetP2d0KBz",
"mode": "list",
"cachedResultName": "Contact Sub-Workflow"
}
},
"type": "@n8n/n8n-nodes-langchain.toolWorkflow",
"position": [100, 200],
"id": "c160a514-fc69-4b5b-b545-ee987836a821",
"name": "contactScraping"
},
{
"parameters": {
"promptType": "define",
"text": "={{ $json.message.text }}",
"options": {
"systemMessage": "=# System\nYou extract business contacts from databases.\n\n# Available Tools\n### contactScraping:\nExtract contacts to spreadsheet after getting search criteria.\n\n# Instructions\n- Introduce yourself as Contact Extractor\n- Ask what contacts they need today\n- Replace spaces with '+' in queries\n- Example: 'new york usa' becomes 'new+york+usa'\n\n# Sample Flow\n- User: 'Hello'\n- Bot: 'Hi! I'm Contact Extractor. What contacts do you want to find?'\n- User: 'Marketing managers in London'\n- Bot: 'Great! What industries should I focus on?'\n- User: 'Tech companies'\n- Tool call with proper JSON format"
}
},
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [-160, -40],
"id": "15090ffe-d584-4154-b279-eaaaf800519b",
"name": "Contact Agent"
}
]
}
And my subworkflow that’s causing the JSON error:
{
"name": "Contact Sub-Workflow",
"nodes": [
{
"parameters": {
"mode": "raw",
"jsonOutput": "={\n\"searchParams\":\n{{ $json.searchData }}\n}",
"options": {}
},
"type": "n8n-nodes-base.set",
"position": [-680, 160],
"id": "gbe8dece-f3d0-464f-a621-4fd4a0fd1182",
"name": "Parse JSON"
},
{
"parameters": {
"url": "https://api.hunter.io/v2/domain-search",
"sendBody": true,
"jsonBody": "={\n \"domain\": \"{{ $json.targetDomain }}\",\n \"limit\": 100,\n \"type\": \"professional\"\n}"
},
"type": "n8n-nodes-base.httpRequest",
"position": [-320, 160],
"id": "b94b7dac-facb-4111-8c99-aec46d6e082g",
"name": "Contact API"
}
]
}
The error happens at the Parse JSON node. I want to extract contacts to my spreadsheet but can’t get past this JSON validation issue. Any ideas what’s wrong with my JSON structure?