Created
August 14, 2022 22:39
-
-
Save markodayan/d4a31202ebe21c9a82894cf761803a1c to your computer and use it in GitHub Desktop.
Deserialise - receive serialised payload and deserialise into a golang struct variable
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
// Step 1 | |
serialised := receiveSerialisedPayload(); | |
// Step 2 - We can deserialise into a struct with knowledge of the payload structure | |
type Person struct { | |
Name string `json:"name"` | |
Age int `json:"age"` | |
Job string `json:"job"` | |
} | |
var data Person | |
json.Unmarshal(serialised, &data) | |
fmt.Println(data.Name) // Chris Redfield | |
fmt.Println(data.Age) // 30 | |
fmt.Println(data.Job) // STARS soldier |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment