{"record":{"id":"9e51aa218a214611","repo":"influxdata/influxdb","slug":"failed-to-parse-json-response","errorCode":null,"errorMessage":"failed to parse JSON response: {}","messagePattern":"failed to parse JSON response: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"influxdb3_client/src/lib.rs","lineNumber":50,"sourceCode":"    Bytes(#[source] reqwest::Error),\n\n    #[error(\"failed to serialize the request body: {0}\")]\n    RequestSerialization(#[source] serde_json::Error),\n\n    #[error(\n        \"provided parameter ('{name}') could not be converted \\\n        to a statment parameter\"\n    )]\n    ConvertQueryParam {\n        name: String,\n        #[source]\n        source: iox_query_params::Error,\n    },\n\n    #[error(\"invalid UTF8 in response: {0}\")]\n    InvalidUtf8(#[from] FromUtf8Error),\n\n    #[error(\"failed to parse JSON response: {}\", reqwest_description(.0))]\n    Json(#[source] reqwest::Error),\n\n    #[error(\"failed to parse plaintext response: {}\", reqwest_description(.0))]\n    Text(#[source] reqwest::Error),\n\n    #[error(\"server responded with error [{code}]: {message}\")]\n    ApiError {\n        code: StatusCode,\n        message: String,\n        /// Machine-readable error code from JSON error responses, if present.\n        error_code: Option<String>,\n    },\n\n    #[error(\"failed to send {method} {url} request: {}\", reqwest_description(.source))]\n    RequestSend {\n        method: Method,\n        url: String,\n        #[source]","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/influxdb3_client/src/lib.rs#L32-L68","documentation":"Error::Json in influxdb3_client::Error, raised when the HTTP response body cannot be parsed as JSON while the client tries to decode an API response. The underlying reqwest::Error is attached as source and reqwest_description adds reqwest's own detail (including any decode error text, hence the trailing {}). This means the server returned a body the client did not expect to be non-JSON (or truncated/malformed JSON).","triggerScenarios":"Calling a Client method that expects a JSON response (query/health/catalog endpoints) when the server returns malformed JSON, an empty or truncated body, an HTML error page (proxy/ingress error), or a body with wrong Content-Type.","commonSituations":"Hitting InfluxDB 3 behind a load balancer or reverse proxy that returns an HTML 502/503 page; pointing the client at the wrong port or service; a version mismatch where the endpoint returns plaintext; network truncation mid-body.","solutions":["Log the full source chain (err.source()) and the raw response body to see what the server actually returned","Verify the URL points at the InfluxDB 3 HTTP API, not a UI, proxy, or another service port","Bypass proxy/LB and call the server directly to rule out an HTML error page being injected","Check client and server versions match (influxdb3 binary vs client crate)","Enable retry with backoff if the cause is a transient network truncation"],"exampleFix":"// before\nlet resp = client.api_v3_query_sql(...).await?;\n// after\nmatch client.api_v3_query_sql(...).await {\n    Ok(resp) => resp,\n    Err(e) if matches!(e, influxdb3_client::Error::Json(_)) => {\n        // inspect source chain / fall back to text handling\n        eprintln!(\"json decode failed: {e:#}\");\n        return Err(e);\n    }\n}","handlingStrategy":"try-catch","validationCode":"// no pre-call validation possible; optionally verify endpoint reachability first\n// e.g. GET {base_url}/health returns 200 with a JSON body","typeGuard":"fn is_json_parse_error(e: &influxdb3_client::Error) -> bool {\n    matches!(e, influxdb3_client::Error::Json(_))\n}","tryCatchPattern":"match result {\n    Err(influxdb3_client::Error::Json(src)) => {\n        log::error!(\"json decode failed: {src:#}\");\n        // fall back: fetch raw bytes and inspect/sniff the body\n    }\n    other => other?,\n}","preventionTips":["Ensure requests go directly to the InfluxDB 3 API, not through proxies that emit HTML error pages","Monitor for 5xx responses which often carry non-JSON bodies","Pin compatible client/server versions","When unsure, read raw bytes first and decode JSON yourself to control the failure mode"],"tags":["http","json","influxdb3","client"],"backgroundTag":"invalid-json-response","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}