title: Unmarshal dynamic YAML to map of structs
body: <p>I'm trying to unmarshal the following YAML (using gopkg.in/yaml.v2):</p>
  
  <pre><code>m:
    - unit: km
      formula: magnitude / 1000
      testFixtures:
        - input: 1000
          expected: 1
  l:
    - unit: ml
      formula: magnitude * 1000
      testFixtures:
        - input: 1
          expected: 1000
  </code></pre>
  
  <p>With the following code:</p>
  
  <pre><code>type ConversionTestFixture struct {
      Input    float64 `yaml:"input"`
      Expected float64 `yaml:"expected"`
  }
  
  type conversionGroup struct {
      Unit         string                  `yaml:"unit"`
      Formula      string                  `yaml:"formula"`
      TestFixtures []ConversionTestFixture `yaml:"testFixtures"`
  }
  conversionGroups := make(map[string]conversionGroup)
  
  err = yaml.Unmarshal([]byte(raw), &amp;conversionGroups)
  if err != nil {
      return
  }
  
  fmt.Println("conversionGroups", conversionGroups)
  </code></pre>
  
  <p>But it gives me the following error:</p>
  
  <pre><code>Error: Received unexpected error:
  
  yaml: unmarshal errors:
  
    line 1: cannot unmarshal !!map into []map[string]main.conversionGroup
  </code></pre>
  
  <p>The top level properties are dynamic so I need to parse them as string, every other key in the structure will always be the same, hence the structs for those parts. How can I parse this?</p>
  
  <p>(full code are at <a href="https://github.com/tirithen/unit-conversion/blob/master/convert.go#L84" rel="nofollow noreferrer">https://github.com/tirithen/unit-conversion/blob/master/convert.go#L84</a>)</p>