Json encoder produces base64

68 views
Skip to first unread message

Shane H

unread,
Apr 6, 2020, 2:03:50 AM4/6/20
to golang-nuts
I know that it's documented that the json encoder will produce base64 "Array and slice values encode as JSON arrays, except that []byte encodes as a base64-encoded string", but I am getting a base64 response when I pass in a string

response := []string

w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(response); err != nil{
    // handle error
}

Will produce the base64 equivalent of the URL, instead of json.

Given that every time I have asked for help on this list I have discovered that it's something that I am doing wrong, I do NOT mind if someone helpfully points me toward the documentation I am misreading

Jakob Borg

unread,
Apr 6, 2020, 2:24:10 AM4/6/20
to Shane H, golang-nuts
Hi Shane,

This doesn't happen with your example: https://play.golang.org/p/C3zb6Qyx-2f

Can you provide a small example of when it does happen?

//jb

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/4e145a21-52cb-4393-bda0-b11d11a471ed%40googlegroups.com.

Shane H

unread,
Apr 6, 2020, 2:40:23 AM4/6/20
to golang-nuts
OMG, it was my *test* that was modifying the value... Thanks so much for your time


On Monday, April 6, 2020 at 4:24:10 PM UTC+10, Jakob Borg wrote:
Hi Shane,

This doesn't happen with your example: https://play.golang.org/p/C3zb6Qyx-2f

Can you provide a small example of when it does happen?

//jb

On 6 Apr 2020, at 08:03, Shane H <sha...@gmail.com> wrote:

I know that it's documented that the json encoder will produce base64 "Array and slice values encode as JSON arrays, except that []byte encodes as a base64-encoded string", but I am getting a base64 response when I pass in a string

response := []string

w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(response); err != nil{
    // handle error
}

Will produce the base64 equivalent of the URL, instead of json.

Given that every time I have asked for help on this list I have discovered that it's something that I am doing wrong, I do NOT mind if someone helpfully points me toward the documentation I am misreading

--
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 golan...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages