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

encoding/json: marshalling interfaces #11951

ThePiachu opened this issue Jul 30, 2015 · 2 comments

encoding/json: marshalling interfaces #11951

ThePiachu opened this issue Jul 30, 2015 · 2 comments


Copy link

I recently started implementing some interfaces for my structures and I was surprised to find that the default JSON encoder appears to try encoding the interfaces as if they were variables in structures. So for example if we have:

type Foo interface{

type Bar struct {
ImportantVariable string

The encoded JSON would look like:

Which is kind of silly, since Foo will never be anything other than null.

I think it would be useful for JSON to check if an imported variable is only an interface, not a struct or any other data structure, and ignore it completely if it is.

Copy link

Here it's not null:

And here it's a string:

I think this is working.

@bradfitz bradfitz changed the title JSON marshalling interfaces encoding/json: marshalling interfaces Jul 30, 2015
Copy link

Sorry, I meant empt interface. One way or the other, it's trying to denote there is a variable there when we only have an interface that doesn't hold any data itself.

@golang golang locked and limited conversation to collaborators Aug 5, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

3 participants