Open hic003cih opened 4 years ago
Here is an example of how you marshal data in Go to JSON. Also important, this video shows how the case of an identifier - lowercase or uppercase, determines whether or not the data can be exported. Here is an example of how you marshal data in Go to JSON. Also important, this video shows how the case of an identifier - lowercase or uppercase, determines whether or not the data can be exported. Here is an example of how you marshal data in Go to JSON. Also important, this video shows how the case of an identifier - lowercase or uppercase, determines whether or not the data can be exported.
package main
import (
"encoding/json"
"fmt"
)
type person struct {
First string
Last string
Age int
}
func main() {
p1 := person{
First: "James",
Last: "Bond",
Age: 32,
}
p2 := person{
First: "Miss",
Last: "Moneypenny",
Age: 27,
}
people := []person{p1, p2}
fmt.Println(people)
bs, err := json.Marshal(people)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(bs))
}