Skip to content

Instantly share code, notes, and snippets.

@markodayan
Created August 14, 2022 22:39
Show Gist options
  • Save markodayan/d4a31202ebe21c9a82894cf761803a1c to your computer and use it in GitHub Desktop.
Save markodayan/d4a31202ebe21c9a82894cf761803a1c to your computer and use it in GitHub Desktop.
Deserialise - receive serialised payload and deserialise into a golang struct variable
// 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