I’m encountering a malformed JSON error in my n8n automation
I’ve developed a contact extraction system in n8n that retrieves business leads and inputs them into Google Sheets. The primary workflow invokes a subworkflow, yet I’m facing this error:
The ‘JSON Output’ in item 0 contains invalid JSON.
This problem arises in the JSON processing node within my subworkflow. I’m attempting to gather contact information from a data scraping API and automatically fill my spreadsheet.
Setup of the main workflow:
{
"name": "contactExtractor",
"nodes": [
{
"parameters": {
"name": "contactScraping",
"description": "=Utilize this function to gather contacts when your search criteria is complete.\n\nThe input format must be:\n\n[\n {\n \"region\": [\n \"REGION1+HERE\",\n \"REGION2+HERE\"\n ],\n \"company_type\": [\n \"TYPE1+HERE\",\n \"TYPE2+HERE\"\n ],\n \"position\": [\n \"ROLE1+HERE\",\n \"ROLE2+HERE\"\n ]\n }\n]",
"workflowId": {
"__rl": true,
"value": "9xyz3WIetP7d1KBc",
"mode": "list",
"cachedResultName": "Contact Sub-Workflow"
}
},
"type": "@n8n/n8n-nodes-langchain.toolWorkflow",
"position": [120, 200],
"id": "c891a514-fc69-4b5b-b545-abc123456",
"name": "contactScraping"
},
{
"parameters": {
"promptType": "define",
"text": "={{ $json.message.text }}",
"options": {
"systemMessage": "=# Role\nYou are a contact extraction assistant.\n\n# Available Tools\n### contactScraping:\nExtract business contacts and save to spreadsheet.\n\n# Guidelines\n- Request clarification when necessary\n- Collect location, type of company, and job roles\n- Substitute spaces with '+' in queries\n- Present yourself as Contact Assistant\n\n# Example Interaction\n- User: \"Hello\"\n- Assistant: \"Hi! I'm your Contact Assistant. What kind of contacts would you like to find today?\"\n- User gives their criteria\n- Call contactScraping with the correct JSON format"
}
},
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [-150, -40],
"id": "xyz123-agent",
"name": "Contact Agent"
}
]
}
Configuration of the subworkflow:
{
"name": "Contact Sub-Workflow",
"nodes": [
{
"parameters": {
"url": "https://api.extractor.com/v2/business-scraper/runs",
"sendBody": true,
"jsonBody": "={\n \"getEmails\": true,\n \"getPhones\": true,\n \"maxResults\": 300,\n \"searchUrl\": \"{{ $json.searchURL }}\"\n}",
"authentication": "genericCredentialType"
},
"type": "n8n-nodes-base.httpRequest",
"position": [-300, 180],
"id": "scraper-node",
"name": "Business Scraper"
},
{
"parameters": {
"mode": "raw",
"jsonOutput": "={\n\"searchCriteria\":\n{{ $json.searchCriteria }}\n}"
},
"type": "n8n-nodes-base.set",
"position": [-650, 180],
"id": "json-processor",
"name": "JSON"
}
]
}
The aim is for extracted contacts to be automatically added to my Google Sheet. Any thoughts on what might be triggering the JSON parsing issue?