Decode JSON keys having hyphen or dash

(Ram Mohan) #1

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.

(Norbert Melzer) #2

Can you please use the playground to provide an example?

As far as I can remember this worked for me…


Seems to work in both directions:

(Ram Mohan) #3

Thanks for quick reply.