title: How can I make use of offset value in enconding/json's UnmarshalTypeError for better error handling?
body: <p>A little over a year ago, Go added an <code>Offset</code> value to the <code>json.UnmarshalTypeError</code> type (see closed issue <a href="https://github.com/golang/go/issues/9693" rel="nofollow noreferrer">here</a> for context). The purpose behind the offset value makes sense, but I'm not sure how it can be used when reading a go http response body, which is of type <code>io.ReadCloser</code>.</p>
  
  <pre><code>// An UnmarshalTypeError describes a JSON value that was
  // not appropriate for a value of a specific Go type.
  type UnmarshalTypeError struct {
      Value  string       // description of JSON value - "bool", "array",   "number -5"
      Type   reflect.Type // type of Go value it could not be assigned to
      Offset int64        // error occurred after reading Offset bytes
  }
  </code></pre>
  
  <p>For example:</p>
  
  <pre><code>var body CustomType
  decoderErr := json.NewDecoder(response.Body).Decode(&amp;body)
  
  if decoderErr != nil {
  
      if typeError, ok := decoderErr.(*json.UnmarshalTypeError); ok {
          // Do something with typeError.Offset here
      }
  
  
  }
  </code></pre>
  
  <p>At the point of the error getting caught, I've already read from <code>response.Body</code> via <code>json.NewDecoder...</code>. I'm looking for a way to read <code>response.Body</code> again, but only up to the point of the error by using the Offset value in typeError. </p>