By default byte slices are marshalled as Base64 strings and byte arrays are converted as is:
func main() {
type Foo struct {
ByteSlice []byte
ByteArray [6]byte
}
foo := Foo {
ByteSlice: []byte{0, 0, 0, 1, 2, 3},
ByteArray: [6]byte{0, 0, 0, 1, 2, 3},
}
text, _ := json.Marshal(foo)
fmt.Printf("%s", text)
}
Output:
{"ByteSlice":"AAAAAQID","ByteArray":[0,0,0,1,2,3]}
Is there a way to use hex string conversion for byte slices?