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: Capitalization in field tags not handled correctly when unmarshalling #28190

Closed
ToadKing opened this issue Oct 13, 2018 · 2 comments

Comments

@ToadKing
Copy link

If you try to unmarshal a JSON string with entries with identical keys but different cases, the correct key may not be chosen.

Test Program:

package main

import (
	"encoding/json"
	"fmt"
)

type testStruct struct {
	Testone string `json:"testone"`
}

func main() {
	testStr := `
	{
		"testone": "one",
		"testOne": "two"
	}`

	var s testStruct
	json.Unmarshal([]byte(testStr), &s)
	fmt.Printf("testone = %s\n", s.Testone)
}

Expected output: testone = one
Actual output: testone = two

Tested on Go Playground - go1.11.1

https://play.golang.org/p/zMeyW9Zgfnz

@mvdan
Copy link
Member

mvdan commented Oct 13, 2018

Dup of #14750?

@ToadKing
Copy link
Author

Looks like it, closing this issue.

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