proposal: encoding/json: add an option `omitempty` to json.Encoder #19763
Labels
Milestone
Comments
Another way to do the same thing seems a bit overkill. How often do you want to omit every single empty field, and there are so many of them? Remember that there are plenty of third-party json encoders out there. IMO encoding/json should stay simple. |
The biggest question seems to be whether package P generating json of package Q's data structures should be able to change the way package Q's data structures encode. If different packages using Q's data disagree about whether to omitempty, it seems like that might lead to confusion. That's a big consequence for the convenience of saving a few characters. |
It still doesn't seem like it should be a global option (instead of per-field or per-type), and no one replied to that. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Now, encoding/json should omit empty value if json tag contains
omitempty
:But this is too annoying if many fields should omit empty value.
Can we add an option
omitempty
to json.Encoder?, e.g.The text was updated successfully, but these errors were encountered: