Skip to content

encoding/json: Capitalization in field tags not handled correctly when unmarshalling #28190

@ToadKing

Description

@ToadKing

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

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