Last active
August 6, 2021 11:37
-
-
Save percybolmer/d8693131282fef5d7a5aaf4d9d78d5fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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