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: No way to unmarshal empty string field into struct #29760

Closed
darkfeline opened this issue Jan 16, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@darkfeline
Copy link

commented Jan 16, 2019

There doesn't appear to be a way to unmarshal a JSON field with an empty string key into a struct.

For example https://play.golang.org/p/on_EMTAPGV2

package main

import (
	"encoding/json"
	"fmt"
)

func main() {
	data := []byte(`{"": "foo", "spam": "egg"}`)
	var obj struct {
		Thing string `json:""`
		Spam  string `json:"spam"`
	}
	json.Unmarshal(data, &obj)
	fmt.Printf("%#v", obj)
}
@bontibon

This comment has been minimized.

Copy link
Contributor

commented Jan 16, 2019

Duplicate of #22518

@agnivade

This comment has been minimized.

Copy link
Member

commented Jan 16, 2019

Yep.

@agnivade agnivade closed this Jan 16, 2019

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.