I am working with an API that, frustratingly, has field names that vary for the same value. For example, one API response could look like this:
{
"PersonFirstName": "John",
"PersonLastName": "Smith"
}
Run Code Online (Sandbox Code Playgroud)
while another looks like this:
{
"FirstNm": "John",
"LastNm": "Smith"
}
Run Code Online (Sandbox Code Playgroud)
Suppose then I had a struct which I would like to decode my JSON to. It might look like this:
type Name struct {
FirstName string
LastName string
}
Run Code Online (Sandbox Code Playgroud)
Typically I would just be able to do …