My goal is to send a struct in JSON format.
The problem is, the struct's fields are mostly [][]byte.
The current solution that I can think of:
- Reiterate the fields and do
string(field1). - do
atob(field1)in the front end.
I think the second solution is the better approach. Anyway, if there is a built in arg to json.Marshal a struct to UTF-8 instead of base64, it would be great.
Reproducible code main.go
package main
type response1 struct {
Page int
Fruits []string
Names [][]byte
}
func main() {
res1D := &response1{
Page: 1,
Fruits: []string{"apple", "peach", "pear"},
Names: [][]byte{[]byte("jack"), []byte("james")}}
res1B, _ := json.Marshal(res1D)
fmt.Println("res1B", string(res1B))
}