jsonify.md (1050B)
1 --- 2 title: jsonify 3 linktitle: jsonify 4 description: Encodes a given object to JSON. 5 date: 2017-02-01 6 publishdate: 2017-02-01 7 lastmod: 2020-04-13 8 categories: [functions] 9 menu: 10 docs: 11 parent: "functions" 12 keywords: [strings,json] 13 signature: ["jsonify INPUT", "jsonify OPTIONS INPUT"] 14 workson: [] 15 hugoversion: 16 relatedfuncs: [plainify] 17 deprecated: false 18 aliases: [] 19 --- 20 21 Jsonify encodes a given object to JSON. 22 23 To customize the printing of the JSON, pass a dictionary of options as the first 24 argument. Supported options are "prefix" and "indent". Each JSON element in 25 the output will begin on a new line beginning with *prefix* followed by one or 26 more copies of *indent* according to the indentation nesting. 27 28 29 ``` 30 {{ dict "title" .Title "content" .Plain | jsonify }} 31 {{ dict "title" .Title "content" .Plain | jsonify (dict "indent" " ") }} 32 {{ dict "title" .Title "content" .Plain | jsonify (dict "prefix" " " "indent" " ") }} 33 ``` 34 35 See also the `.PlainWords`, `.Plain`, and `.RawContent` [page variables][pagevars]. 36 37 [pagevars]: /variables/page/