title: How to decode JSON based on object type in Golang
body: <p>If you have the following JSON structure:</p>
  
  <pre><code>[
    {
      "type": "home",
      "name": "house #1",
      ... some number of properties for home #1
    },
    {
      "type": "bike",
      "name": "trek bike #1",
      ... some number of properties for bike #1
    },
    {
      "type": "home",
      "name": "house #2",
      ... some number of properties for home #2
    }
  ]
  </code></pre>
  
  <p>How do you decode this in Golang to a struct without knowing what each type is until you unmarshall the object. It seems like you would have to do this unmarshalling twice.</p>
  
  <p>Also from what I can tell, I should probably be using the RawMessage to delay the decoding.  But I am not sure how this would look.</p>
  
  <p>Say I had the following structs:</p>
  
  <pre><code>type HomeType struct {
    Name                  string       `json:"name,omitempty"`
    Description           string       `json:"description,omitempty"`
    Bathrooms             string       `json:"bathrooms,omitempty"`
    ... more properties that are unique to a home
  }
  
  type BikeType struct {
    Name                  string       `json:"name,omitempty"`
    Description           string       `json:"description,omitempty"`
    Tires                 string       `json:"tires,omitempty"`
    ... more properties that are unique to a bike
  }
  </code></pre>
  
  <p>Second question.  Is it possible to do this in streaming mode? For when this array is really large?</p>
  
  <p>Thanks</p>