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
Contributor

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)
}
@ghost
Copy link

ghost commented Jan 16, 2019

Duplicate of #22518

@agnivade
Copy link
Contributor

Yep.

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

No branches or pull requests

3 participants