I have a poorly structured json response that is returned by a science api.
It basically returns a list of Fields and then separately an array of string arrays which list the data from those fields in the order of the fields returned.
I am having trouble marshalling the result into a struct, I'm assuming, because there are no json tags to attach to the data struct (since it's just an array of string values, despite providing a response model of the data in that array.).
type Response struct {
Fields []string `json:"fields"`
Data []ScienceThings `json:"data"`
}
type ScienceThings struct {
Name string
UiName string
Diameter float64
Density float64
Albedo float64
Perihelion float64
...
I seem to be able to get the result and the .Data but am having zero luck marshalling it into the data object to then output it in my test example - before I start going to town on actually using it. I'm using the typical GoFiber stanzas to get this, namely...
var SbObjects Response
json.Unmarshal(body, &SbObjects)
if err != nil {
fmt.Print(err.Error())
os.Exit(1)
}
but the result is the proper model but just with blanks and 0's even though it does list the correct number of records. How do I marshall the non-name/value paired json into the ScienceThings struct? My google-fu has failed to find a good solution here.