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: marshal map[string]interface{} with error get empty object #26889

meilihao opened this issue Aug 9, 2018 · 1 comment


None yet
2 participants
Copy link

commented Aug 9, 2018

What version of Go are you using (go version)?

go version go1.11beta3 linux/amd64

Does this issue reproduce with the latest release?

go version go1.10.3 linux/amd64

What did you do?

func main() {
	err := errors.New("abc")
	m := map[string]interface{}{
		"error": err,
	data, _ := json.Marshal(m)

What did you expect to see?


What did you see instead?


This comment has been minimized.

Copy link

commented Aug 9, 2018

You're marshaling an interface. And it so happens that the errors package returns a struct with no exported fields, hence {}:

If you want to print the error string, use "error": err.Error().

@mvdan mvdan closed this Aug 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.