I have a json feed, and am trying to check if a struct within a struct exists.
type feed struct {
Video struct {
Name string `json:"name"`
}
}
And here's the unmarshal process:
data:= &feed{}
err := json.Unmarshal([]byte(structuredData), data)
if err != nil {
return err
}
In some cases, Video
exists and in other cases, it doesn't. I would like to validate this in an if statement, something like if data.Video != nil
but this doesn't seem to compile (I get invalid Operation
). How do I check whether Video
exists or not?