Created
December 29, 2019 07:44
-
-
Save arifsetyawan/86386cbbe78bb8d0c6d0fb6bfb989ae7 to your computer and use it in GitHub Desktop.
Json Marshal and Unmarshal
This file contains 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
type User struct { | |
firstName string `json:"first_name"` | |
lastName string `json:"last_name"` | |
} | |
userObj = User{ | |
firstName: "Arif", | |
lastName: "Setyawan" | |
} | |
// ENCODE ======================================= | |
outputBytes, _ := json.Marshal(userObj); | |
fmt.Println(string(outputBytes)); // { "first_name": "Arif", "last_name": "Setyawan" } | |
// DECODE ======================================= | |
var decodedUser User | |
err := json.Unmarshal(outputBytes, &decodedUser) | |
fmt.Printf("%+v", decodedUser) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment