

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: JSON Syntax
incomplete
2: Decoding JSON
incomplete
3: JSON Review
incomplete
4: Unmarshal JSON
incomplete
5: Marshal JSON
incomplete
6: XML
incomplete
7: Why Use XML?
incomplete
8: map[string]interface{}
incomplete
This lesson's interactive features are locked, please to keep using them
If there is a way to unmarshal JSON data, there must be a way to marshal it as well. The json.Marshal function converts a Go struct into a slice of bytes representing JSON data.
type Board struct {
Id int `json:"id"`
Name string `json:"name"`
TeamId int `json:"team"`
TeamName string `json:"team_name"`
}
board := Board{
Id: 1,
Name: "API",
TeamId: 9001,
TeamName: "Backend",
}
data, err := json.Marshal(board)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(data))
// {"id":1,"name":"API","team":9001,"team_name":"Backend"}
Complete the marshalAll function. It accepts a slice of "items", which can be of any type. The expectation is that they are structs of various forms. It should return a slice of slices of bytes (I didn't stutter) [][]byte.