Skip to content

Instantly share code, notes, and snippets.

@vaguecoder
Last active December 16, 2021 18:00
Show Gist options
  • Save vaguecoder/8ed8424f3757abd3d88bf73bdf7db5df to your computer and use it in GitHub Desktop.
Save vaguecoder/8ed8424f3757abd3d88bf73bdf7db5df to your computer and use it in GitHub Desktop.
JSON Marshal-Unmarshal vs Encoding-Decoding in Go (golang)
type Character struct {
Name string `json:"name"`
Designation []string `json:"designation"`
Age int `json:"age"`
Moves []Move `json:"moves"`
}
type Move struct {
Name string `json:"move"`
Power int `json:"power"`
}
var (
data = []Character{
{
Name: "Monkey D Luffy",
Designation: []string{
"King of the Pirates",
"Captain of Straw Hats",
"Rubber Man",
},
Age: 17,
Moves: []Move{
{"Gum Gum Bazooka", 2500},
{"Gum Gum Gatling", 2000},
},
},
{
Name: "Rovanova Zoro",
Designation: []string{
"World's Greatest Swordsman",
"First Mate of Straw Hats",
"Pirate Hunter",
},
Age: 19,
Moves: []Move{
{"108 Caliber Phoenix", 2000},
{"Lion's Strike", 1500},
},
},
{
Name: "Nami",
Designation: []string{
"Navigator",
"Pirate Thief",
},
Age: 18,
Moves: []Move{
{"Thunderbolt Tempo", 1000},
{"Clima-Tact", 800},
},
},
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment