JSNoob JSNoob - 1 year ago 49
JSON Question

Parse JSON with field name containing underscore

So I have JSON like this

{"Name":"Jame","Age":6,"Original_Name":"Jameson"}


In order to get "Name" and "Age" in Go, I just need to use a corresponding struct

type Result struct {
Name string
Age int
}


But how do I get the field "Original_Name" since I cannot use underscore in go?

Answer Source

Does this work:

type Result struct {
  Name string
  Age int
  Originalname string `json:"Original_Name"`
}