gohugoio/hugo · error

too many arguments to jsonify

Error message

too many arguments to jsonify

What it means

`jsonify` accepts at most two arguments: an optional options map (with `indent`, `prefix`, `noHTMLEscape`) followed by the object to encode. Three or more arguments hit the switch default and return this error. With zero arguments it silently returns an empty string, so this error is specifically about passing 3+.

Source

Thrown at tpl/encoding/encoding.go:111

	)

	switch len(args) {
	case 0:
		return "", nil
	case 1:
		obj = args[0]
	case 2:
		var m map[string]any
		m, err = hmaps.ToStringMapE(args[0])
		if err != nil {
			break
		}
		if err = mapstructure.WeakDecode(m, &opts); err != nil {
			break
		}
		obj = args[1]
	default:
		err = errors.New("too many arguments to jsonify")
	}

	if err != nil {
		return "", err
	}

	buff := bp.GetBuffer()
	defer bp.PutBuffer(buff)
	e := json.NewEncoder(buff)
	e.SetEscapeHTML(!opts.NoHTMLEscape)
	e.SetIndent(opts.Prefix, opts.Indent)
	if err = e.Encode(obj); err != nil {
		return "", err
	}
	b = buff.Bytes()
	// See https://github.com/golang/go/issues/37083
	// Hugo changed from MarshalIndent/Marshal. To make the output
	// the same, we need to trim the trailing newline.

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Pass options as a single map: `{{ jsonify (dict "indent" " ") $obj }}`.
  2. To encode multiple values, combine them first: `{{ jsonify (dict "a" $a "b" $b) }}` or `{{ jsonify (slice $a $b) }}`.
  3. Check parenthesization so the object is the last (second) argument of the call.

Example fix

<!-- before -->
{{ jsonify "" "  " $data }}
<!-- after -->
{{ jsonify (dict "indent" "  ") $data }}
Defensive patterns

Strategy: validation

Validate before calling

{{/* jsonify takes at most (options, value): */}}
{{ jsonify (dict "indent" "  ") .Params }}

Prevention

When it happens

Trigger: `{{ jsonify (dict "indent" " ") $a $b }}` — trying to encode two objects; `{{ jsonify " " "\n" $obj }}` — passing prefix/indent as separate strings instead of an options dict (the pre-0.61 style); appending extra pipeline arguments.

Common situations: Migrating from very old Hugo versions or other template engines where jsonify took separate indent arguments; attempting to encode multiple values in one call instead of wrapping them in a dict/slice; mis-nested parentheses in the template making one call receive another call's arguments.

Related errors


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