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

Projects
None yet
2 participants
@ToadKing
Copy link

commented Oct 13, 2018

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

This comment has been minimized.

Copy link
Member

commented Oct 13, 2018

Dup of #14750?

@ToadKing

This comment has been minimized.

Copy link
Author

commented Oct 13, 2018

Looks like it, closing this issue.

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.