How to Fix: JSON parameter need to be an object: Unexpected token in JSON at position 0
n8n expected valid JSON data but received a String or HTML.
What Causes It?
You are using a node (like HTTP Request or Set) and passing data that you think is a JSON object, but it is actually just a plain text string. Or, an API returned an HTML error page (like a 502 Bad Gateway) instead of the expected JSON data.
Plain English Explanation
"n8n speaks JSON. If you hand it a regular sentence or a website's HTML code instead of JSON, it gets confused and throws this error."
Code Examples
// Passing a string instead of an object to a node expecting JSON
const data = "{\"name\": \"Alice\"}";// Parsing the string into a true JSON object first
const data = JSON.parse("{\"name\": \"Alice\"}");Step-by-Step Fix
- 1
Check the output of the node *immediately before* the error.
- 2
If the data is a stringified JSON (looks like JSON but is wrapped in quotes), use a Code node to parse it: `return [{ json: JSON.parse($input.item.json.myString) }];`
- 3
If the data is coming from an HTTP request, ensure the 'Response Format' in the HTTP node is set to 'JSON' instead of 'String'.
Prevention Tips
- Always use the 'JSON' tab in the n8n execution viewer to inspect if your data is truly an object or just a string.
- Add error-handling (try/catch) inside Code nodes when parsing external data.
FAQs & Interview Prep
Why Interviewers Ask About This
Medium. Data transformation errors are the most common day-to-day issue an automation engineer faces.
How do I fix this if an external API fails randomly?
Use the 'Error Trigger' node in n8n to catch workflows that fail due to bad API responses, and send yourself a Slack or Email alert.