Empty JSON responses handled gracefully
HTTP Request node no longer throws parsing errors when APIs return empty response bodies with JSON content-type, returning {} instead.
The HTTP Request node was throwing "Invalid JSON in response body" errors when APIs returned successful responses with empty bodies, even though the content-type header specified application/json and content-length was 0. This caused workflows to fail on valid API responses.
Now the node handles empty JSON responses gracefully by returning an empty object {} instead of attempting to parse an empty string. The fix applies to both autodetect and explicit JSON response format modes, ensuring consistent behavior regardless of how users configure the node.
This matters because many REST APIs return empty bodies on successful operations like POST requests that create resources, status 201 responses with no body, or DELETE operations that return no content. Workflows that integrate with these APIs should not fail due to empty but valid responses.
The change is isolated to the HTTP Request node implementation in the nodes-base package.
View Original GitHub Description
Summary
- Handle empty JSON HTTP responses without throwing parsing errors when body content is empty.
- Return
{}for empty JSON bodies in bothResponse Format: Autodetectand explicitResponse Format: JSONpaths. - Add regression tests in
HttpRequestV3.test.tsfor empty-body JSON responses withcontent-length: 0.
How to test
- Run:
pushd packages/nodes-base >/dev/null && pnpm test nodes/HttpRequest/test/node/HttpRequestV3.test.ts && popd >/dev/null - Run:
pushd packages/nodes-base >/dev/null && NODE_OPTIONS=--max-old-space-size=8192 pnpm lint && NODE_OPTIONS=--max-old-space-size=8192 pnpm typecheck && popd >/dev/null
Related Linear tickets, Github issues, and Community forum posts
- https://linear.app/n8n/issue/GHC-7520
- fixes #27782
Review / Merge checklist
- PR title and summary are descriptive. (conventions)
- Docs updated or follow-up ticket created.
- Tests included.
- PR Labeled with
release/backport(if the PR is an urgent fix that needs to be backported)