You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was getting terribly confused today trying to figure this out:
----------
package main
import (
"encoding/json"
"fmt"
)
var s =
`{"owner_email":"first","owner":"second"}`
func main() {
var data struct {
Owner string `json:"owner_email"`
}
if err := json.Unmarshal([]byte(s), &data); err != nil {
fmt.Printf("Malformed JSON: %v", err)
return
}
fmt.Printf("data: %+v", data)
}
----------
I only cared about the "owner_email" field, so was just trying to select it.
Unfortunately, the decoding of the later "owner" field overwrites it. I'm not
sure it's a bug, but I'm leaning that way. My reason for thinking it's a bug is that the
`json:"owner_email"` is declaring that the JSON name for that field is
"owner_email", and thus the "owner" field should *not* be matching
against it, even if it was the only piece of the input.
This is easy enough to work around (I just have to rename the Owner field); I'm not sure
whether this qualifies as a clear enough bug to warrant a technical change to the API.
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: