I'm using JSON to get some values into a variable from an external source.

I have a type like this that json.Unmarshal puts values into:

    type Frame struct {
        Type  string
        Value map[string]interface{}
    }

    var data Frame

After unmarshal, I can access a the type by: data.Type

but if I try doing something like:

    if data.Type == "image" {
        fmt.Printf("%s\n", data.Value.Imagedata)
    }

The compiler complains about no such value data.Value.Imagedata.

So my question is, how do I reference properties in Go that I know will be there depending on some condition?

Doing this works:

    type Image struct {
        Filename string
    }

    type Frame struct {
        Type  string
        Value map[string]interface{}
    }

But that isn't very flexible as I will be receiving different Values.

go
Edit
Report