{"record":{"id":"81b849e66886eae1","repo":"ducaale/xh","slug":"json-values-are-not-supported-in-multipart-fields-to-curl","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/to_curl.rs","lineNumber":384,"sourceCode":"    }\n\n    if let Some(raw) = args.raw {\n        if args.form {\n            cmd.header(\"content-type\", FORM_CONTENT_TYPE);\n        } else {\n            cmd.header(\"content-type\", JSON_CONTENT_TYPE);\n            cmd.header(\"accept\", JSON_ACCEPT);\n        }\n\n        cmd.opt(\"-d\", \"--data\");\n        cmd.arg(raw);\n    } else if args.request_items.is_multipart() {\n        // We can't use .body() here because we can't look inside the multipart\n        // form after construction and we don't want to actually read the files\n        for item in args.request_items.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                    cmd.opt(\"-F\", \"--form\");\n                    cmd.arg(format!(\"{key}={value}\"));\n                }\n                RequestItem::DataFieldFromFile { key, value, .. } => {\n                    cmd.opt(\"-F\", \"--form\");\n                    cmd.arg(format!(\"{key}=<{value}\"));\n                }\n                RequestItem::FormFile {\n                    key,\n                    file_name,\n                    file_type,\n                    file_name_header,\n                } => {\n                    cmd.opt(\"-F\", \"--form\");\n                    let mut val = format!(\"{key}=@{file_name}\");\n                    if let Some(file_type) = file_type {","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/ducaale/xh/blob/2404aceecc08b0b2d100fedc96f57745cd5904dc/src/to_curl.rs#L366-L402","documentation":"When the request items form a multipart body, to_curl uses curl -F to describe the form; curl cannot express raw JSON values as field values in -F, and xh will not read files to inline them. So JSON-typed fields (=: and =@ JSON-file items) are rejected outright during translation.","triggerScenarios":"Running `xh --curl` (or --httpie/--print-curl translation) on a command that combines -f/--multipart with JSON fields, e.g. `xh -f POST url 'data:={\"a\":1}'` or a JsonFieldFromFile item in a multipart request.","commonSituations":"Users mixing --multipart with := JSON value syntax; converting an existing JSON-body request to multipart for file upload while keeping JSON fields; automated curl export of a mixed request.","solutions":["Drop --multipart and send JSON fields normally (non-multipart) if no file upload is truly needed","Replace the JSON field with a plain string field (=) if the server accepts it","Pass the JSON as an uploaded file part (key@file.json) instead of an inline JSON value","Send two requests: one multipart upload and one JSON API call, then translate each separately"],"exampleFix":"// before\nxh --curl -f POST example.org/upload 'meta:={\"version\":2}' f@data.bin\n// after\nxh --curl -f POST example.org/upload 'meta@meta.json' f@data.bin","handlingStrategy":"validation","validationCode":"fn multipart_has_json(items: &[RequestItem]) -> bool {\n    items.iter().any(|i| matches!(\n        i,\n        RequestItem::JsonField(..) | RequestItem::JsonFieldFromFile(..)\n    ))\n}\nif is_multipart && multipart_has_json(&items) {\n    eprintln!(\"remove := / :=@ fields when using --multipart\");\n    std::process::exit(2);\n}","typeGuard":"fn is_json_request_item(i: &RequestItem) -> bool {\n    matches!(i, RequestItem::JsonField(..) | RequestItem::JsonFieldFromFile(..))\n}","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"JSON values are not supported in multipart\") => {\n        eprintln!(\"convert := fields to = fields or use key@file.json\");\n    }\n    r => r?,\n}","preventionTips":["Never mix :=/:=@ JSON fields with --multipart","Use key@file.json to send JSON content as a file part","When exporting to curl, pre-check request items for JSON-typed fields"],"tags":["cli","curl","multipart","json"],"backgroundTag":"unsupported-operation","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"}