Skip to content

Instantly share code, notes, and snippets.

@yukin01
Created May 6, 2020 16:20
Show Gist options
  • Save yukin01/648a91b84c3223233862a833c6cc71ec to your computer and use it in GitHub Desktop.
Save yukin01/648a91b84c3223233862a833c6cc71ec to your computer and use it in GitHub Desktop.
Convert json struct to map in Go
import "encoding/json"
func structToMap(s interface{}) map[string]interface{} {
m := make(map[string]interface{})
b, _ := json.Marshal(s)
json.Unmarshal(b, &m)
return m
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment