{"record":{"id":"29dc1a07b0af38cd","repo":"ducaale/xh","slug":"json-values-are-not-supported-in-multipart-fields","errorCode":null,"errorMessage":"JSON values are not supported in multipart fields","messagePattern":"JSON values are not supported in multipart fields","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/request_items.rs","lineNumber":366,"sourceCode":"                    text_fields.push((key, fs::read_to_string(path)?));\n                }\n                RequestItem::FormFile { .. } => unreachable!(),\n                RequestItem::HttpHeader(..) => {}\n                RequestItem::HttpHeaderFromFile(..) => {}\n                RequestItem::HttpHeaderToUnset(..) => {}\n                RequestItem::UrlParam(..) => {}\n                RequestItem::UrlParamFromFile(..) => {}\n            }\n        }\n        Ok(Body::Form(text_fields))\n    }\n\n    fn body_as_multipart(self) -> Result<Body> {\n        let mut form = multipart::Form::new();\n        for item in self.items {\n            match item {\n                RequestItem::JsonField(..) | RequestItem::JsonFieldFromFile(..) => {\n                    return Err(anyhow!(\"JSON values are not supported in multipart fields\"));\n                }\n                RequestItem::DataField { key, value, .. } => {\n                    form = form.text(key, value);\n                }\n                RequestItem::DataFieldFromFile { key, value, .. } => {\n                    let path = expand_tilde(value);\n                    form = form.text(key, fs::read_to_string(path)?);\n                }\n                RequestItem::FormFile {\n                    key,\n                    file_name,\n                    file_type,\n                    file_name_header,\n                } => {\n                    let mut part = file_to_part(expand_tilde(file_name))?;\n                    if let Some(file_type) = file_type {\n                        part = part.mime_str(&file_type)?;\n                    }","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/ducaale/xh/blob/2404aceecc08b0b2d100fedc96f57745cd5904dc/src/request_items.rs#L348-L384","documentation":"Multipart bodies consist of named parts with text or binary content; raw JSON typed values from `key:=value` items have no multipart representation. `body_as_multipart` therefore rejects any `RequestItem::JsonField`/`JsonFieldFromFile` item with this error.","triggerScenarios":"Running `xh --multipart POST :8080 name=John count:=2` (or `--form` with multipart resolved), where a `:=` or `@file:=` item is present among the request items.","commonSituations":"Uploading files with `--multipart` while keeping JSON fields from an earlier JSON-mode command line; generated command lines that append `:=` items regardless of body mode.","solutions":["Convert `:=` items to plain `key=value` text fields when in multipart mode.","Remove `--multipart`/`--form` if you need typed JSON values in the body.","Send the JSON part separately, e.g. as a JSON string field: `json='{\"count\":2}'`."],"exampleFix":"// before\nxh --multipart POST :8080 file@photo.png count:=2\n// after\nxh --multipart POST :8080 file@photo.png count=2","handlingStrategy":"validation","validationCode":"# guard: multipart must not contain := items\nif echo \"$args\" | grep -q -- '--multipart' && echo \"$args\" | grep -q ':='; then\n  echo 'JSON (:=) fields are invalid in multipart'; exit 1\nfi","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"not supported in multipart\") => {\n        eprintln!(\"convert := items to plain text fields for multipart\");\n    }\n    other => other?,\n}","preventionTips":["Use only key=value and key@file items with --multipart.","Send structured data as a JSON string field if needed.","Sanitize request-item lists before switching body modes."],"tags":["http","multipart","json","cli"],"backgroundTag":"incompatible-source-type","analyzedSha":"2404aceecc08b0b2d100fedc96f57745cd5904dc","analyzedAt":"2026-09-13T19:13:33.814Z","contentChangedAt":"2026-09-13T19:13:33.814Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}