{"record":{"id":"7a6eec7a2996ece7","repo":"ducaale/xh","slug":"json-values-are-not-supported-in-form-fields","errorCode":null,"errorMessage":"JSON values are not supported in Form fields","messagePattern":"JSON values are not supported in Form fields","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/request_items.rs","lineNumber":343,"sourceCode":"                | RequestItem::HttpHeaderFromFile(..)\n                | RequestItem::HttpHeaderToUnset(..)\n                | RequestItem::UrlParam(..)\n                | RequestItem::UrlParamFromFile(..) => continue,\n            };\n            let json_path = nested_json::parse_path(&raw_key)?;\n            body = nested_json::insert(body, &json_path, value)\n                .map_err(|e| e.with_json_path(raw_key))?\n                .into();\n        }\n        Ok(Body::Json(body.unwrap_or(Value::Null)))\n    }\n\n    fn body_as_form(self) -> Result<Body> {\n        let mut text_fields = Vec::<(String, String)>::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 Form fields\"));\n                }\n                RequestItem::DataField { key, value, .. } => text_fields.push((key, value)),\n                RequestItem::DataFieldFromFile { key, value, .. } => {\n                    let path = expand_tilde(value);\n                    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> {","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/ducaale/xh/blob/2404aceecc08b0b2d100fedc96f57745cd5904dc/src/request_items.rs#L325-L361","documentation":"When building an `application/x-www-form-urlencoded` body, every request item must be a plain string key/value. `RequestItem::JsonField` (the `key:=value` syntax) carries typed JSON values that cannot be represented as form text fields, so `body_as_form` aborts with this error.","triggerScenarios":"Mixing `=` (data) and `:=` (raw JSON) operators without `--json` mode being in effect, e.g. `xh --form POST :8080 name=John count:=2` — the `:=` item triggers the error inside `body_as_form`.","commonSituations":"Copying JSON-mode examples and adding `--form`/`-f` for file uploads; scripts that append `:=` fields to form submissions; forgetting that `-f` forces form serialization for all fields.","solutions":["Remove the `:=` (raw JSON) fields or convert them to `=` string fields when using form mode.","Drop `--form`/`-f` if you actually want a JSON body, and use `=`/`:=` fields freely.","Use `--multipart` with file fields only, keeping value fields as plain `key=value`."],"exampleFix":"// before\nxh --form POST :8080 name=John count:=2\n// after\nxh POST :8080 name=John count:=2","handlingStrategy":"validation","validationCode":"# guard: form mode must not contain := items\nif [[ \"$*\" == *--form* || \"$*\" == *\" -f \"* ]] && echo \"$*\" | grep -q ':='; then\n  echo 'JSON (:=) fields are invalid with --form'; exit 1\nfi","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"not supported in Form fields\") => {\n        eprintln!(\"use = fields with --form, or drop --form for := fields\");\n    }\n    other => other?,\n}","preventionTips":["Pick one body style per request: JSON (=/:=) or form (= only).","Never combine -f/--form with := items in generated commands.","Review command builders that template operators across modes."],"tags":["http","form","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"}