Skip to content

encoding/json: Unmarshal doesn't use preferred match #47984

@zigo101

Description

@zigo101

What version of Go are you using (go version)?

$ go version
go version go1.17 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

package main

import "encoding/json"
import "fmt"

type A struct {
	Bar string `json:"Bar"`
	//BAR string `json:"bar"`
}

var s = []byte(`{
	"Bar": "1",
	"bar": "2"
}`)

func main() {
	var a A
	_ = json.Unmarshal(s, &a)
	fmt.Println(a.Bar) // 2
}

What did you expect to see?

prints 1

What did you see instead?

prints 2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions