goccy / go-json

Fast JSON encoder/decoder compatible with encoding/json for Go
MIT License
3.12k stars 148 forks source link

Possibility to turn off *all* escaping? #514

Open karalabe opened 5 months ago

karalabe commented 5 months ago

I've hit this limitation with the Go stdlib and the new json/v2 they proposed too, and it seems to be in this library too. Specifically, that every user type is forced through an ASCII/HTML escaper. Whilst the latter can be disabled, AFAIK the former cannot.

We have an API where we hex encode some big blobs (10-20MB) via a custom MarshalJSON method, but due to all the json libs forcing an escape run over the produced hex string, the latency shoots up quite a bit (50-100ms), which is too high for us. Wondering if there could be a way to signal to the encoder from a type that "I know my output is correct, append it verbatim and don't do escaping"?