{"record":{"id":"8100cd46504316ae","repo":"gohugoio/hugo","slug":"too-many-arguments-to-jsonify","errorCode":null,"errorMessage":"too many arguments to jsonify","messagePattern":"too many arguments to jsonify","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/encoding/encoding.go","lineNumber":111,"sourceCode":"\t)\n\n\tswitch len(args) {\n\tcase 0:\n\t\treturn \"\", nil\n\tcase 1:\n\t\tobj = args[0]\n\tcase 2:\n\t\tvar m map[string]any\n\t\tm, err = hmaps.ToStringMapE(args[0])\n\t\tif err != nil {\n\t\t\tbreak\n\t\t}\n\t\tif err = mapstructure.WeakDecode(m, &opts); err != nil {\n\t\t\tbreak\n\t\t}\n\t\tobj = args[1]\n\tdefault:\n\t\terr = errors.New(\"too many arguments to jsonify\")\n\t}\n\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tbuff := bp.GetBuffer()\n\tdefer bp.PutBuffer(buff)\n\te := json.NewEncoder(buff)\n\te.SetEscapeHTML(!opts.NoHTMLEscape)\n\te.SetIndent(opts.Prefix, opts.Indent)\n\tif err = e.Encode(obj); err != nil {\n\t\treturn \"\", err\n\t}\n\tb = buff.Bytes()\n\t// See https://github.com/golang/go/issues/37083\n\t// Hugo changed from MarshalIndent/Marshal. To make the output\n\t// the same, we need to trim the trailing newline.","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/encoding/encoding.go#L93-L129","documentation":"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.","triggerScenarios":"Calling `{{ jsonify $opts $data $extra }}` with three arguments, or any invocation beyond the options-plus-value form.","commonSituations":"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.","solutions":["Pass only the value: `{{ jsonify $data }}`.","Or pass an options map then the value: `{{ jsonify (dict \"indent\" \"  \") $data }}`.","Merge or pre-process multiple data sources into a single value before calling jsonify."],"exampleFix":"// before\n{{ jsonify (dict \"indent\" \"  \") $a $b }}\n// after\n{{ $merged := dict \"a\" $a \"b\" $b }}\n{{ jsonify (dict \"indent\" \"  \") $merged }}","handlingStrategy":"validation","validationCode":"{{ if le (len $args) 2 }}{{ jsonify $args... }}{{ end }}","typeGuard":"func validJsonifyArity(n int) bool { return n <= 2 }","tryCatchPattern":null,"preventionTips":["Pass at most an options map and one value to jsonify.","Merge multiple data sources before encoding.","Avoid positional extras."],"tags":["hugo","template","encoding","jsonify","arity"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}