influxdata/influxdb · error · Error
failed to parse JSON response
Error message
failed to parse JSON response: {} What it means
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).
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
Example fix
// before
let resp = client.api_v3_query_sql(...).await?;
// after
match client.api_v3_query_sql(...).await {
Ok(resp) => resp,
Err(e) if matches!(e, influxdb3_client::Error::Json(_)) => {
// inspect source chain / fall back to text handling
eprintln!("json decode failed: {e:#}");
return Err(e);
}
} Defensive patterns
Strategy: try-catch
Validate before calling
// no pre-call validation possible; optionally verify endpoint reachability first
// e.g. GET {base_url}/health returns 200 with a JSON body Type guard
fn is_json_parse_error(e: &influxdb3_client::Error) -> bool {
matches!(e, influxdb3_client::Error::Json(_))
} Try / catch
match result {
Err(influxdb3_client::Error::Json(src)) => {
log::error!("json decode failed: {src:#}");
// fall back: fetch raw bytes and inspect/sniff the body
}
other => other?,
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to build an http client
- failed to parse plaintext response
- failed to send request
- Cannot parse the given human time
- Cannot parse the timestamp
AI-assisted analysis of influxdata/influxdb@06200ef96b (2026-09-19).
Data as JSON: /api/errors/9e51aa218a214611.
Report an issue: GitHub.
Appendix: source
Thrown at influxdb3_client/src/lib.rs:50
Bytes(#[source] reqwest::Error),
#[error("failed to serialize the request body: {0}")]
RequestSerialization(#[source] serde_json::Error),
#[error(
"provided parameter ('{name}') could not be converted \
to a statment parameter"
)]
ConvertQueryParam {
name: String,
#[source]
source: iox_query_params::Error,
},
#[error("invalid UTF8 in response: {0}")]
InvalidUtf8(#[from] FromUtf8Error),
#[error("failed to parse JSON response: {}", reqwest_description(.0))]
Json(#[source] reqwest::Error),
#[error("failed to parse plaintext response: {}", reqwest_description(.0))]
Text(#[source] reqwest::Error),
#[error("server responded with error [{code}]: {message}")]
ApiError {
code: StatusCode,
message: String,
/// Machine-readable error code from JSON error responses, if present.
error_code: Option<String>,
},
#[error("failed to send {method} {url} request: {}", reqwest_description(.source))]
RequestSend {
method: Method,
url: String,
#[source]View on GitHub (pinned to 06200ef96b)