Skip to content

Json fields with hypen (-) are not decoded properly #83

@fedulovivan

Description

@fedulovivan

Json fields with hypen (-) are not decoded properly (BTW same for original mitchellh/mapstructure).

Minimal reproduction code (tried with go 1.22.5, 1.24)

package main
import (
	"fmt"

	"github.com/go-viper/mapstructure/v2"
)
type Out struct {
	Foo    int `json:"foo"`
	BarBaz int `json:"bar-baz"`
}
func main() {
	in := make(map[string]any)
	in["foo"] = 1
	in["bar-baz"] = 2
	out := new(Out)
	mapstructure.Decode(in, out)
	fmt.Printf("%+v", out)
}

Actual
&{Foo:1 BarBaz:0}
Expected
&{Foo:1 BarBaz:2}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions