Skip to content

How to take an existing Struct and turn it into a Map? #79

@veqryn

Description

@veqryn

This project says in its description: "Go library for decoding generic map values into native Go structures and vice versa."

However, I can't seem to figure out how to do the vice versa part.

Given the following:

type Person struct {
	Name   string
	Age    int
}

p := Person{
	Name: "Foo",
	Age: 30,
}

What function should I call to get this as a result:

m := mapstructure.Encode(p)

fmt.Printf("%#v", m)
// map[string]interface {}{"Age":30, "Name":"Foo"}

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