Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
encoding/json: marshaling nil value stored in interface value doesn't omitempty #16750
If I assign a nil pointer variable to result.Err, the field is not omitted from the marshaled JSON as expected. Instead the field is marshaled as a JSON null.
If I assign the nil literal to result.Err, the field is omitted from the marshaled JSON as expected
This issue is clearly demonstrated here: https://play.golang.org/p/uw6jvKN-qX
Working as intended. If you have
Then if I = 0 it gets omitted, or if S is "" it gets omitted, or if J is nil it gets omitted. But if J is 0 or "", it does not get omitted. That's not considered "empty" for an interface.