Debian Codegraph @

docs/content/en/functions/encoding/Jsonify.md

raw
1 ---
2 title: encoding.Jsonify
3 description: Encodes the given object to JSON.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: [jsonify]
9 returnType: template.HTML
10 signatures: ['encoding.Jsonify [OPTIONS] INPUT']
11 aliases: [/functions/jsonify]
12 ---
13
14 To customize the printing of the JSON, pass an options map as the first
15 argument. Supported options are "prefix" and "indent". Each JSON element in
16 the output will begin on a new line beginning with _prefix_ followed by one or
17 more copies of _indent_ according to the indentation nesting.
18
19 ```go-html-template
20 {{ dict "title" .Title "content" .Plain | jsonify }}
21 {{ dict "title" .Title "content" .Plain | jsonify (dict "indent" " ") }}
22 {{ dict "title" .Title "content" .Plain | jsonify (dict "prefix" " " "indent" " ") }}
23 ```
24
25 ## Options
26
27 The `encoding.Jsonify` function accepts an options map.
28
29 `indent`
30 : (`string`) Indentation to use. Default is "".
31
32 `prefix`
33 : (`string`) Indentation prefix. Default is "".
34
35 `noHTMLEscape`
36 : (`bool`) Whether to disable escaping of problematic HTML characters inside JSON quoted strings. The default behavior is to escape `&`, `<`, and `>` to `\u0026`, `\u003c`, and `\u003e` to avoid certain safety problems that can arise when embedding JSON in HTML. Default is `false`.