gohugoio/hugo · error
failed to detect target data serialization format
Error message
failed to detect target data serialization format
What it means
The first argument to `transform.Remarshal` is the target format name, resolved via `metadecoders.FormatFromString` in `toFormatMark` (tpl/transform/remarshal.go:81-87). If the string doesn't map to a known serialization format, Remarshal cannot know what to emit and fails immediately, before touching the data.
Source
Thrown at tpl/transform/remarshal.go:86
for k, v := range m {
switch t := v.(type) {
case map[string]any:
applyMarshalTypes(t)
case float64:
i := int64(t)
if t == float64(i) {
m[k] = i
}
}
}
}
func toFormatMark(format string) (metadecoders.Format, error) {
if f := metadecoders.FormatFromString(format); f != "" {
return f, nil
}
return "", errors.New("failed to detect target data serialization format")
}
View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Use a supported format name: "json", "yaml", "toml" (or "xml" as a source); fix any typo.
- Check argument order: `transform.Remarshal <format> <data>` — with a pipe, the data comes through the pipe and the format is the literal first argument.
- If the format is computed, print it with `warnf` to confirm it isn't empty or the wrong variable.
Example fix
<!-- before: typo in target format -->
{{ $cfg | transform.Remarshal "tolm" }}
<!-- after -->
{{ $cfg | transform.Remarshal "toml" }} Defensive patterns
Strategy: validation
Validate before calling
{{ $format := "yaml" }}
{{ if not (in (slice "json" "yaml" "yml" "toml" "xml") (lower $format)) }}
{{ errorf "unsupported remarshal target format %q" $format }}
{{ end }} Prevention
- Pass the target format as a literal lowercase string: "json", "yaml", "toml", or "xml"
- If the format comes from site params, whitelist-check it before calling transform.Remarshal
- Don't pass file extensions with dots (".yaml") — use the bare format name
When it happens
Trigger: Calling `{{ $data | transform.Remarshal "ini" }}` or any format string that isn't json, yaml, yml, toml, or xml — including typos ("jsn", "tolm"), or accidentally swapping the argument order so the data string is treated as the format.
Common situations: Argument order confusion (format comes first, then data — pipelines put data last); typoed format names; passing a variable that resolves to empty or to the content instead of the format name.
Related errors
- failed to detect format from content
- transform.Highlight: expects at most 3 arguments
- invalid strict mode; expected one of error, ignore, or warn;
- cannot transform content of Resource of type %T
- error building site: %w
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/5e5106b91f09e2ad.json.
Report an issue: GitHub ↗.