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

  1. Use a supported format name: "json", "yaml", "toml" (or "xml" as a source); fix any typo.
  2. Check argument order: `transform.Remarshal <format> <data>` — with a pipe, the data comes through the pipe and the format is the literal first argument.
  3. 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

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


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/5e5106b91f09e2ad.json. Report an issue: GitHub ↗.