While you can use the solution suggested by Viktor. I do wonder what exactly is the point of the byte type?
I mean byte is just uint8 just like it says above. So really if you want number between 0 and 255 you can just send along the number. This is gonna be more readable than some text encoding of byte using base64 or similar. If you are concerned about space I feel compression will serve you better. But who knows maybe you have perfectly valid reason for sending along byte as string and then converting it back to byte. Cheers PS: just in case this was not about byte but []byte https://golang.org/pkg/encoding/json/#RawMessage On Wednesday, September 14, 2016 at 3:06:41 PM UTC, Luke wrote: > > Hi, > > i have something like: https://play.golang.org/p/j5WhDMUTI- > > type A struct { > Name string `json:"n"` > Typ byte `json:"t"` > } > > JSON string: > > j := `{"n":"test", "t":"x"}` > > > When I try to do > > a := A{} > json.Unmarshal([]byte(j), &a) > > I get error like: *json: cannot unmarshal string into Go value of type > uint8* > > > Any idea how to force unmarshaler to treat one character string as byte > using standard json lib? > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.