gohugoio/hugo · error

too many arguments to jsonify

Error message

too many arguments to jsonify

What it means

The `jsonify` function encodes a value to JSON, optionally with a prefix/indent options map as the first argument. It accepts zero args (empty string), one arg (the value), or two args (options + value). Three or more arguments fall into the default branch at encoding.go:110–111.

Solutions

  1. Pass only the value: `{{ jsonify $data }}`.
  2. Or pass an options map then the value: `{{ jsonify (dict "indent" " ") $data }}`.
  3. Merge or pre-process multiple data sources into a single value before calling jsonify.

Example fix

// before
{{ jsonify (dict "indent" "  ") $a $b }}
// after
{{ $merged := dict "a" $a "b" $b }}
{{ jsonify (dict "indent" "  ") $merged }}
Defensive patterns

Strategy: validation

Validate before calling

{{ if le (len $args) 2 }}{{ jsonify $args... }}{{ end }}

Type guard

func validJsonifyArity(n int) bool { return n <= 2 }

Prevention

When it happens

Trigger: Calling `{{ jsonify $opts $data $extra }}` with three arguments, or any invocation beyond the options-plus-value form.

Common situations: A developer appends an extra argument (e.g. a second data object or a flag) expecting concatenation or merge behavior that jsonify does not provide.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/8100cd46504316ae. Report an issue: GitHub.

Appendix: 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 52c9bd7908)