go-json icon indicating copy to clipboard operation
go-json copied to clipboard

case-insensitive key matching not working with nested structs

Open liberize opened this issue 2 years ago • 1 comments

example:

package main

import (
	"fmt"
	"github.com/goccy/go-json"
)

type Base struct {
	B string `json:"bb"`
}

type Test struct {
	Base
	A string `json:"aA"`
}

func main() {
	b := &Test{}
	err := json.Unmarshal([]byte(`{"Aa":"111","Bb":"222"}`), b)
	fmt.Printf("b: %v, err: %v\n", b, err)
}

prints:

b: &{{} }, err: <nil>

change json:"bB" to json:"bb" then it works:

b: &{{222} 111}, err: <nil>

tested with go 1.14.5 and go-json master

liberize avatar Sep 11 '23 02:09 liberize

I think it was because you may need to change the example input data as well.

xin-tsla avatar Oct 07 '23 18:10 xin-tsla