{"record":{"id":"bb6cb6ee81811277","repo":"influxdata/influxdb","slug":"error-decoding-query-body-0","errorCode":null,"errorMessage":"error decoding query body: {0}","messagePattern":"error decoding query body: (.+?)","errorType":"http","errorClass":"Error::SerdeJson","httpStatus":null,"severity":"error","filePath":"core/iox_v1_query_api/src/error.rs","lineNumber":46,"sourceCode":"    /// Missing parameters for query\n    #[error(\"missing query parameters 'db' and 'q'\")]\n    MissingQueryParams,\n\n    #[error(\"error decoding multipart file upload: {0}\")]\n    MultipartFile(String),\n\n    #[error(\"Invalid UTF8: {message} {error}\")]\n    Utf8 {\n        message: &'static str,\n        error: String,\n    },\n\n    /// Serde decode error\n    #[error(\"error decoding params from url: {0}\")]\n    SerdeUrlDecoding(#[from] serde_urlencoded::de::Error),\n\n    // SerdeJsonError\n    #[error(\"error decoding query body: {0}\")]\n    SerdeJson(#[from] serde_json::Error),\n\n    #[error(\"datafusion error: {0}\")]\n    Datafusion(#[from] DataFusionError),\n\n    #[error(\"error in InfluxQL statement: {0}\")]\n    InfluxqlRewrite(#[from] rewrite::Error),\n\n    #[error(\"must provide only one InfluxQl statement per query\")]\n    InfluxqlSingleStatement,\n\n    #[error(\"must specify a 'db' parameter, or provide the database in the InfluxQL query\")]\n    InfluxqlNoDatabase,\n\n    #[error(\n        \"provided a database in both the parameters ({param_db}) and \\\n        query string ({query_db}) that do not match, if providing a query \\\n        that specifies the database, you can omit the 'database' parameter \\","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/core/iox_v1_query_api/src/error.rs#L28-L64","documentation":"`Error::SerdeJson` wraps `serde_json::Error` and is thrown when a JSON request body cannot be decoded into the v1 API's expected query parameters struct. The `#[from]` conversion makes any JSON deserialization failure in the request body produce this error.","triggerScenarios":"POSTing `application/json` bodies to the query endpoint with malformed JSON, wrong field types (e.g. number where string expected), or unknown/missing required fields in the deserialization target.","commonSituations":"Hand-written JSON payloads with syntax mistakes, clients sending JSON when the endpoint expects urlencoded form data, or schema drift after an API version bump.","solutions":["Validate the JSON body parses and matches the expected schema (fields `db`, `q` as strings).","Ensure the Content-Type is JSON only when the body actually is JSON; otherwise use form encoding.","Deserialize locally with `serde_json::from_str::<Params>` to reproduce and pinpoint the failing field."],"exampleFix":"// before\n{\"db\": 123, \"q\": \"SELECT 1\"}  // wrong type\n// after\n{\"db\": \"mydb\", \"q\": \"SELECT 1\"}","handlingStrategy":"validation","validationCode":"fn json_body_ok(body: &str) -> Result<(), serde_json::Error> {\n    let v: serde_json::Value = serde_json::from_str(body)?;\n    if v.get(\"db\").and_then(|d| d.as_str()).is_none() { return Err(serde_json::Error::custom(\"'db' must be a string\")); }\n    Ok(())\n}","typeGuard":"fn is_serde_json_error(e: &iox_v1_query_api::Error) -> bool {\n    matches!(e, iox_v1_query_api::Error::SerdeJson(_))\n}","tryCatchPattern":"let body = serde_json::json!({\"db\": db, \"q\": q}).to_string();\njson_body_ok(&body)?;\nlet resp = client.post(\"/query\").header(\"content-type\", \"application/json\").body(body).send().await?;","preventionTips":["Serialize request bodies with serde structs rather than hand-writing JSON strings.","Match Content-Type to the actual body encoding (JSON only for JSON bodies).","Validate payloads against the parameter schema in tests after any API version change."],"tags":["rust","http-api","json","deserialization","serde","thiserror"],"backgroundTag":"json-parse-error","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"}