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
Closed

encoding/json: No way to unmarshal empty string field into struct #29760

darkfeline opened this issue Jan 16, 2019 · 2 comments

Comments

@darkfeline
Copy link

@darkfeline darkfeline 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

@bontibon bontibon commented Jan 16, 2019

Duplicate of #22518

@agnivade

This comment has been minimized.

Copy link
Contributor

@agnivade agnivade commented Jan 16, 2019

Yep.

@agnivade agnivade closed this Jan 16, 2019
@golang golang locked and limited conversation to collaborators Jan 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.