francoispqt / gojay

high performance JSON encoder/decoder with stream API for Golang
MIT License
2.11k stars 112 forks source link

Encoder SetEscapeHTML #50

Open veqryn opened 6 years ago

veqryn commented 6 years ago

gojay should support SetEscapeHTML on the Encoder, and should default to true to match the standard library.

For example:

type Stuff struct {
    Thing string
}

v := &Stuff{Thing: `hello <&,.='"'=.,&> world`}

buffer := &bytes.Buffer{}
encoder := gojay.NewEncoder(buffer)
encoder.SetEscapeHTML(false)
_ = encoder.Encode(v)

Should result in: {"Thing":"hello <&,.='\"'=.,&> world"}

While encoder.SetEscapeHTML(true) should result in: {"Thing":"hello \u003c\u0026,.='\"'=.,\u0026\u003e world"} This should also be the default result when using gojay.Marshal