ErrLookupBackground articles › "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected

"Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected

"Invalid JSON response" errors fire when an HTTP call technically succeeds — often with a 200 status — but the response body cannot be parsed as the JSON the client was contractually expecting. Developers meet this family when a proxy, captive portal, WAF, or auth layer swaps in an HTML page, when a connection truncates the body mid-transfer, when a base URL points at the wrong endpoint, or when the server's JSON shape drifts from what the library's parser or schema expects. The messages vary widely ("returned invalid JSON", "Unable to get json response", "judge response is not a JSON object", "Failed to parse API response") but the diagnosis is the same everywhere: capture the raw body, identify which server actually answered, and fix routing, proxies, credentials, or schema alignment.

Distilled from 81 documented records across 28 repositories.

Background

This family sits in the response-handling layer of HTTP clients: after the transport succeeds and the status code is checked, the library calls json.loads() / JSON.parse / json_decode / resp.json() / Jackson readValue / System.Text.Json on the body and the parse throws. From the caller's side it looks paradoxical — the request "worked" but the error mentions JSON. The mechanism is almost always the same: the code assumed a 2xx response implies a JSON body matching a known schema, and something between the client and the real API (or the API itself) violated that assumption.

What actually produces the non-JSON body varies, and the records show recurring patterns across ecosystems. The single most common source is an intermediary returning HTML with status 200: corporate proxies injecting block pages (pnpm records [9][27]), captive portals (octobercms [10][11]), CDN/WAF challenge or consent walls (Yahoo Finance [4], EnableBanking [15], Cryptomus [5]), auth portals and login redirects (Databricks [7], Turso [16], claude-mem [24]). The second big group is misrouting: a base URL pointing at a web UI, docs site, or wrong endpoint instead of the API — DASHSCOPE_API_BASE pointing at the console [2], Databricks api_base hitting the workspace UI [7], claude-mem baseUrl missing the /v1 segment [24], Phabricator's cluster.search aimed at a non-Elasticsearch port [1], Triton api_base missing the /v2/models/<model>/infer or /generate path [17][25].

A third group is not about transport at all but about content: the body parses but has the wrong shape or type. LiteLLM's JSONSchemaValidationError [0] fires when a validated completion isn't even parseable; its llm-judge error [14] fires when the judge returns a JSON array or scalar instead of an object; Turso's inner-result error [22] and k6's json.UnmarshalTypeError path [8] fire when field types drift from the decode target; yt-dlp's Bigo extractor [29] raises when the endpoint returns a JSON list or string instead of the expected envelope. Truncation is a fourth source: dropped connections, proxy size limits, or 10 MB maxBuffer stdout caps in the ECC gh wrappers [3][13] cut the payload mid-JSON so parsing fails on "unexpected end of input."

A notable library-specific quirk: several wrappers swallow the original failure and relabel it. ECC's runGhJson [3][13] catches both the parse error and the underlying command failure, so a gh auth problem surfaces as "returned invalid JSON" with the real error embedded in the tail of the message. PHP's json_decode returning null for both invalid JSON and the literal "null" body can false-positive [5]. And some handlers deliberately embed the offending body in the exception — Databricks [7], Triton [17][25], pnpm [9][27], and k6's error paths make the raw body the primary diagnostic, while others (Yahoo Finance [4], Frankfurter [6]) lose it unless you logged it before parsing.

Common causes

What usually fixes it

Go deeper

Documented occurrences

…and 61 more across the corpus — use search.

Honest provenance: generated on 2026-08-27 from AI-assisted analysis of the linked records. See how records are made.