json-iterator / go

A high-performance 100% compatible drop-in replacement of "encoding/json"
http://jsoniter.com/migrate-from-go-std.html
MIT License
13.43k stars 1.03k forks source link

Support returning non-critical warnings when decoding #570

Open luxas opened 3 years ago

luxas commented 3 years ago

Hi! Thanks for this great project :1st_place_medal: :100:

When decoding JSON, sometimes you just want to inform the users about problems in the serialized content, rather than returning an error or staying silent. I realize that the Attachment field of https://pkg.go.dev/github.com/json-iterator/go#Iterator could be used for this purpose (thanks for adding that in advance!) by a custom warning-supporting decoder, but it would be nice to add this field specifically for this purpose, so it could be re-used more generally.

The two main uses I see for it would be to warn instead of error when there are duplicate or unknown fields when decoding. I can make a PR with this change if accepted. Would you be open to this?