| 1 |
--- |
| 2 |
title: encoding.Jsonify |
| 3 |
description: Returns the given object encoded 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 |
## Usage |
| 15 |
|
| 16 |
To customize the printing of the JSON, pass an options map as the first |
| 17 |
argument. Supported options are "prefix" and "indent". Each JSON element in |
| 18 |
the output will begin on a new line beginning with _prefix_ followed by one or |
| 19 |
more copies of _indent_ according to the indentation nesting. |
| 20 |
|
| 21 |
```go-html-template |
| 22 |
{{ dict "title" .Title "content" .Plain | jsonify }} |
| 23 |
{{ dict "title" .Title "content" .Plain | jsonify (dict "indent" " ") }} |
| 24 |
{{ dict "title" .Title "content" .Plain | jsonify (dict "prefix" " " "indent" " ") }} |
| 25 |
``` |
| 26 |
|
| 27 |
## Options |
| 28 |
|
| 29 |
The `encoding.Jsonify` function accepts an options map. |
| 30 |
|
| 31 |
`indent` |
| 32 |
: (`string`) Indentation to use. Default is "". |
| 33 |
|
| 34 |
`prefix` |
| 35 |
: (`string`) Indentation prefix. Default is "". |
| 36 |
|
| 37 |
`noHTMLEscape` |
| 38 |
: (`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`. |