mapstructure icon indicating copy to clipboard operation
mapstructure copied to clipboard

Decode underscore value

Open mussa572 opened this issue 3 years ago • 3 comments

Hi I have Jason field k8s_version which contain underscore. However I have noticed that I am not able to decode values with _. Just wondering if its a bug or required me to add anything

mussa572 avatar Aug 21 '22 01:08 mussa572

You can decode those if you tag them like this.

	// UserAccount - this type is purposely showing the emailskip field in the data is not present
	type User struct {
		Name     string
		IsActive bool `mapstructure:"is_active"`
	}

and the data with the _

	uinput := map[string]interface{}{
		"name":      "UserB",
		"is_active": true,
	}

I found that looking through the notes in the actual source file and in the comments it speaks on how to do it.

Printed Output

main.User{Name:"UserB", IsActive:true}

lkendrickd avatar Sep 14 '22 19:09 lkendrickd

nonono this is bug image

SkyWingZhang avatar Feb 21 '23 08:02 SkyWingZhang

so ga very good image

SkyWingZhang avatar Feb 21 '23 10:02 SkyWingZhang