{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/encoding/encoding.go#L93-L129","documentation":"`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+.","triggerScenarios":"`{{ 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.","commonSituations":"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.","solutions":["Pass options as a single map: `{{ jsonify (dict \"indent\" \"  \") $obj }}`.","To encode multiple values, combine them first: `{{ jsonify (dict \"a\" $a \"b\" $b) }}` or `{{ jsonify (slice $a $b) }}`.","Check parenthesization so the object is the last (second) argument of the call."],"exampleFix":"<!-- before -->\n{{ jsonify \"\" \"  \" $data }}\n<!-- after -->\n{{ jsonify (dict \"indent\" \"  \") $data }}","handlingStrategy":"validation","validationCode":"{{/* jsonify takes at most (options, value): */}}\n{{ jsonify (dict \"indent\" \"  \") .Params }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["jsonify accepts one value, optionally preceded by an options dict — never more","When piping, remember the piped value counts as the final argument","Wrap multiple values in a dict or slice before jsonify"],"tags":["hugo","templates","json","arguments"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}