JSNoob JSNoob - 4 months ago 10
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

Does this work:

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