gohugoio/hugo · error
unmarshal takes 1 or 2 arguments
Error message
unmarshal takes 1 or 2 arguments
What it means
`transform.Unmarshal` requires either one argument (the data: a string, json.RawMessage, or Resource) or two (an options map first, then the data). Zero arguments or three-plus fail this arity check immediately, before any decoding is attempted.
Source
Thrown at tpl/transform/unmarshal.go:40
"github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/resources/resource"
"github.com/gohugoio/hugo/common/hashing"
"github.com/gohugoio/hugo/common/types"
"github.com/mitchellh/mapstructure"
"github.com/gohugoio/hugo/parser/metadecoders"
"github.com/spf13/cast"
)
// Unmarshal unmarshals the data given, which can be either a string, json.RawMessage
// or a Resource. Supported formats are JSON, TOML, YAML, and CSV.
// You can optionally provide an options map as the first argument.
func (ns *Namespace) Unmarshal(args ...any) (any, error) {
if len(args) < 1 || len(args) > 2 {
return nil, errors.New("unmarshal takes 1 or 2 arguments")
}
var data any
decoder := metadecoders.Default
if len(args) == 1 {
data = args[0]
} else {
m, ok := args[0].(map[string]any)
if !ok {
return nil, errors.New("first argument must be a map")
}
var err error
data = args[1]
decoder, err = decodeDecoder(m)
if err != nil {View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Call it as `transform.Unmarshal DATA` or `transform.Unmarshal OPTIONS_MAP DATA`.
- Bundle all options into a single dict: `{{ transform.Unmarshal (dict "delimiter" ";") $csv }}`.
- When piping, remember the piped value is appended as the final argument — only the options map should precede it.
Example fix
<!-- before -->
{{ transform.Unmarshal "delimiter" ";" $csv }}
<!-- after -->
{{ transform.Unmarshal (dict "delimiter" ";") $csv }} Defensive patterns
Strategy: validation
Validate before calling
{{/* unmarshal (options?, data): */}}
{{ $d := unmarshal $yaml }} or {{ $d := unmarshal (dict "delimiter" ";") $csv }} Prevention
- Call transform.Unmarshal with 1 or 2 args: optional options map, then the data
- When piping, the piped resource/string is the last argument — pass only the options map explicitly
- Don't pass multiple documents; unmarshal one at a time
When it happens
Trigger: `{{ transform.Unmarshal }}` with nothing; `{{ transform.Unmarshal $opts $data $extra }}`; pipeline mistakes like `{{ $a $b | transform.Unmarshal $c }}` where the pipe adds a final argument beyond two.
Common situations: Forgetting that piped values count as the last argument (`$data | transform.Unmarshal $opts` is fine — two args — but adding more breaks it); passing CSV options as separate arguments instead of one dict; splitting an unquoted string into multiple arguments.
Related errors
- need at least 2 arguments to append
- must provide a Resource and optionally an options map
- operator argument must be string type
- can't evaluate the array by no match argument or more than o
- invalid arguments supplied to `time`
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/3dfd87e8dac1bd4b.json.
Report an issue: GitHub ↗.