title: How to unmarshal an array of string encoded floats to an array of floats?
body: <p>I'm trying to unmarshal some json data I get from a web service. I have simplified the problem which is shown in the code below. My question is can I make version (c) in the code work.. </p>
  
  <p>I know it works for single number values as shown for "timestamp" by adding the option ",string" to the json annotation. But I can't figure out how or if this works for arrays of string encoded numbers too. (See "conversions" in the example json listed in the code)</p>
  
  <pre><code>package main
  
  import (
      "encoding/json"
      "fmt"    
  )
  
  //version (a)
  type JsonData1 struct {
      TimeStamp   uint64          `json:"timestamp,string"`
      Conversions [][2]string     `json:"conversions"`
  }
  
  //version (b)
  type JsonData2 struct {
      TimeStamp   uint64              `json:"timestamp,string"`
      Conversions [][2]json.Number    `json:"conversions"` 
  }
  
  //version (c)
  type JsonData3 struct {
      TimeStamp   uint64          `json:"timestamp,string"`
      Conversions [][2]float32    `json:"conversions"` 
  }
  
  const incomingJson string = `{"timestamp": "1407178369", "conversions": [["1.021", "2.124"], ["2.432", "3.923"], ["3.234", "5.001"]]}`
  
  func main() {
      var data1 JsonData1
      if err1 := json.Unmarshal([]byte(incomingJson), &amp;data1); err1 != nil {
          fmt.Println("Error unmarshaling with struct JsonData1")
          fmt.Println("--&gt; ", err1.Error())
      } else {
          fmt.Println("Success unmarshaling with struct JsonData1")
          fmt.Println("--&gt; ", data1)
      }
  
      var data2 JsonData2
      if err2 := json.Unmarshal([]byte(incomingJson), &amp;data2); err2 != nil {
          fmt.Println("Error unmarshaling with struct JsonData2")
          fmt.Println("--&gt; ", err2.Error())
      } else {
          fmt.Println("Success unmarshaling with struct JsonData2")
          fmt.Println("--&gt; ", data2)
      }    
  
      var data3 JsonData3
      if err3 := json.Unmarshal([]byte(incomingJson), &amp;data3); err3 != nil {
          fmt.Println("Error unmarshaling with struct JsonData3")
          fmt.Println("--&gt; ", err3.Error())
      } else {
          fmt.Println("Success unmarshaling with struct JsonData3")
          fmt.Println("--&gt; ", data3)
      }  
  }
  </code></pre>
  
  <p>If i compile and run the code I get this output:</p>
  
  <pre><code>Success unmarshaling with struct JsonData1
  --&gt;  {1407178369 [[1.021 2.124] [2.432 3.923] [3.234 5.001]]}
  Success unmarshaling with struct JsonData2
  --&gt;  {1407178369 [[1.021 2.124] [2.432 3.923] [3.234 5.001]]}
  Error unmarshaling with struct JsonData3
  --&gt;  json: cannot unmarshal string into Go value of type float32
  </code></pre>
  
  <p>You can run the code here: <a href="http://play.golang.org/p/4TC0IgCI8H" rel="nofollow">http://play.golang.org/p/4TC0IgCI8H</a></p>
  
  <p>Is there a way to achieve unmarshaling into struct version (c)? Thanks for your help!</p>