title: Golang parse JSON array into data structure
body: <p>I am trying to parse a file which contains JSON data:</p>
  
  <pre><code>[
    {"a" : "1"},
    {"b" : "2"},
    {"c" : "3"}
  ]
  </code></pre>
  
  <p>Since this is a JSON array with dynamic keys, I thought I could use:</p>
  
  <pre><code>type data map[string]string
  </code></pre>
  
  <p>However, I cannot parse the file using a <code>map</code>:</p>
  
  <pre><code>c, _ := ioutil.ReadFile("c")
  dec := json.NewDecoder(bytes.NewReader(c))
  var d data
  dec.Decode(&amp;d)
  
  
  json: cannot unmarshal array into Go value of type main.data
  </code></pre>
  
  <p>What would be the most simple way to parse a file containing a JSON data is an array (only string to string types) into a Go struct?</p>
  
  <p><strong>EDIT:</strong> To further elaborate on the accepted answer -- it's true that my JSON is an array of maps. To make my code work, the file should contain:</p>
  
  <pre><code>{
    "a":"1",
    "b":"2",
    "c":"3"
  }
  </code></pre>
  
  <p>Then it can be read into a <code>map[string]string</code></p>