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

  1. Log the full source chain (err.source()) and the raw response body to see what the server actually returned
  2. Verify the URL points at the InfluxDB 3 HTTP API, not a UI, proxy, or another service port
  3. Bypass proxy/LB and call the server directly to rule out an HTML error page being injected
  4. Check client and server versions match (influxdb3 binary vs client crate)
  5. 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

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.

Related errors


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)