Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for omitnil #53

Closed
ivanjaros opened this issue Oct 12, 2024 · 5 comments
Closed

Add support for omitnil #53

ivanjaros opened this issue Oct 12, 2024 · 5 comments

Comments

@ivanjaros
Copy link

I have been fighting Go's json for years when it comes to handling of null values.
Go's implementation only has omitempty and it treats {}, [] and null as one and the same. But {} and [] are information of intent whereas null is not. I have been handling this issue in various ways and presently I am using a fork of native json library, after years of using Goccy and clean-up code that stripped null values from raw json. This was still more performant than using native json. Sadly the entire standard library lacks in performance, after a decade of neglect. But goccy has been lagging with issues and I no longer trust it, hence the fork.

In short, please add configuration option to not render null values. Also add omitnil or omitnull tag, so we can target maps and slices individually when we want to distinguish nil and empty values, since maps and slices are pointers in Go.

@zzhaolei
Copy link

I think this is related to golang/go#45669

@dsnet
Copy link
Collaborator

dsnet commented Oct 15, 2024

I suspect that your use-case is already satisfied by the omitzero option that that originated in this module and has since been back-ported to the "encoding/json" package for the upcoming release of Go.

@ivanjaros
Copy link
Author

Technically it solves my issue but only on struct tag basis. I want a global configuration targeting only nils specifically, not all zero values.

@dsnet
Copy link
Collaborator

dsnet commented Nov 20, 2024

#61 adds a caller-specified option to omit all zero struct fields.

@dsnet dsnet closed this as completed Nov 20, 2024
@ivanjaros
Copy link
Author

global omitzero will get rid of false or 0, i don't know how else to communicate i want to get rid of null values in json, not default values in Go.

i'll stick with my forked native json because this brings no value to me. cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants