title: convert interface{} to certain type
body: <p>I am developing web service that will receive JSON. Go converts types too strict. </p>
  
  <p>So I did following function to convert <code>interface{}</code> in <code>bool</code></p>
  
  <pre><code>func toBool(i1 interface{}) bool {
      if i1 == nil {
          return false
      }
      switch i2 := i1.(type) {
      default:
          return false
      case bool:
          return i2
      case string:
          return i2 == "true"
      case int:
          return i2 != 0
      case *bool:
          if i2 == nil {
              return false
          }
          return *i2
      case *string:
          if i2 == nil {
              return false
          }
          return *i2 == "true"
      case *int:
          if i2 == nil {
              return false
          }
          return *i2 != 0
      }
      return false
  }
  </code></pre>
  
  <p>I believe that function is still not perfect and I need functions to convert <code>interface{}</code> in <code>string</code>, <code>int</code>, <code>int64</code>, etc</p>
  
  <p>So my question: Is there library (set of functions) in <code>Go</code> that will convert <code>interface{}</code> to certain types</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>My web service receive JSON. I decode it in <code>map[string]interface{}</code> I do not have control on those who encode it.</p>
  
  <p>So all values I receive are <code>interface{}</code> and I need way to cast it in certain types.</p>
  
  <p>So it could be <code>nil</code>, <code>int</code>, <code>float64</code>, <code>string</code>, <code>[...]</code>, <code>{...}</code> and I wish to cast it to what it should be. e.g. <code>int</code>, <code>float64</code>, <code>string</code>, <code>[]string</code>, <code>map[string]string</code> with handling of all possible cases including <code>nil</code>, wrong values, etc</p>
  
  <p><strong>UPDATE2</strong></p>
  
  <p>I receive <code>{"s": "wow", "x":123,"y":true}</code>, <code>{"s": 123, "x":"123","y":"true"}</code>, <code>{a:["a123", "a234"]}</code>, <code>{}</code></p>
  
  <pre><code>var m1 map[string]interface{}
  json.Unmarshal(b, &amp;m1)
  s := toString(m1["s"])
  x := toInt(m1["x"])
  y := toBool(m1["y"])
  arr := toStringArray(m1["a"])
  </code></pre>