Standard library / encoding/json

encoding/json.UnmarshalTypeError

Reports an incompatible JSON value. Value, Type, Offset, Struct and Field identify the mismatch; decoding may have already modified the destination. Expected stdout: 'true Count int\n'.

Formal Syntax & Structure

go syntaxgo
type UnmarshalTypeError struct {  Value  string  Type   reflect.Type  Offset int64  Struct string  Field  string}

Working Example

Example Snippetgo
package main
import (  "encoding/json"  "errors"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  var x struct{ Count int }  e := json.Unmarshal([]byte(`{"Count":"x"}`), &x)  var t *json.UnmarshalTypeError  fmt.Println(errors.As(e, &t), t.Field, t.Type)}
Go Reference