Closed 4cecoder closed 1 year ago
package main
import (
"fmt"
"encoding/json"
)
type User struct {
Name string
}
func main() {
// created the user object
user := &User{Name: "Frank"}
// turning the object into json
b, err := json.Marshal(user)
if err != nil {
fmt.Println(err)
return
}
// write to Http response instead of printing line
fmt.Println(string(b))
}
Output:
{"Name":"Frank"}
this one is actually pretty simple!