Decode JSON keys having hyphen or dash

I tried below JSON for decoding using json package. which has hyphen/dash

{ “user-name”: “ram”}

structure i have defined as below

type user struct {

Username string json:”user-name”

}

surprisingly it’s not able to decode the value. what is the reason behind this ? and how i can decode it to structure and access the value in GO. because this is third party legacy format which i cant change.

2 Likes

Can you please use the playground to provide an example?

As far as I can remember this worked for me…


edit:

Seems to work in both directions:

https://play.golang.org/p/BJECXoRU59V

2 Likes

Thanks for quick reply.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.