Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active August 6, 2021 11:37
Show Gist options
  • Save percybolmer/d8693131282fef5d7a5aaf4d9d78d5fc to your computer and use it in GitHub Desktop.
Save percybolmer/d8693131282fef5d7a5aaf4d9d78d5fc to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"log"
)
func main() {
testData := []byte(`{
"user":"test",
"email":"[email protected]"
}`)
var user User
// Here we pass our User into unmarshal, it takes an empty interface, so it doesn't matter what type it is
err := json.Unmarshal(testData, &user)
if err != nil {
log.Fatal(err)
}
log.Println("Found user, ", user)
}
type User struct {
User string
Email string
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment