tidwall / sjson

Set JSON values very quickly in Go
MIT License
2.4k stars 165 forks source link

Mismatched Encoding / Decoding of Byte Values #60

Open jshlbrd opened 2 years ago

jshlbrd commented 2 years ago

great project, thanks for your contribution to open source!

i'm consistently experiencing some unusual behavior when setting byte values (the impacted code is here and here): when byte values are set, they are converted to a string and then (by default) encoded using the standard library's json.Marshal function, but (for reasons i don't understand) it appears that json.Unmarshal does not decode the value back to the original byte value. here's an example showing how SJSON's behavior mimics the behavior of the standard library, plus a "working example" using strconv to get the original bytes.

as an aside, was it a design decision for SJSON to not encode bytes as a base64 encoded string? that is how the standard library works and it would also solve the problem of consistently decoding back to the original value.

thanks!