Standard library / encoding/json
encoding/json.HTMLEscape()
Append JSON with HTML-sensitive characters and U+2028/U+2029 escaped inside strings. This is not a general HTML sanitizer. Expected stdout: '"\\u003c\\u003e\\u0026"\n'.
Formal Syntax & Structure
go syntaxgo
func HTMLEscape(dst *bytes.Buffer, src []byte)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| dst | *bytes.Buffer | Destination buffer; output is appended. |
| src | []byte | Input JSON bytes. |
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; json.HTMLEscape(&b, []byte(`"<>&"`)); fmt.Println(b.String()) }