Standard library / encoding/json
encoding/json.Encoder.SetEscapeHTML()
Control escaping of HTML-sensitive characters in JSON strings. The default is true; disabling it is appropriate only when the output context is safe. Expected stdout: '"<tag>"\n'.
Formal Syntax & Structure
go syntaxgo
func (enc *Encoder) SetEscapeHTML(on bool)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| on | bool | Whether to escape HTML-sensitive characters. |
Working Example
Example Snippetgo
package main
import ( "bytes" "encoding/json" "fmt")
func must(e error) { if e != nil { panic(e) }}
func main() { var b bytes.Buffer e := json.NewEncoder(&b) e.SetEscapeHTML(false) must(e.Encode("<tag>")) fmt.Print(b.String())}