Golang encoding/json.UnmarshalTypeError type and function example

package encoding/json

An UnmarshalTypeError describes a JSON value that was not appropriate for a value of a specific Go type.

Golang encoding/json.UnmarshalTypeError type and function usage example

 switch err.(type) {
 case ct.ValidationError:
 fmt.Println("Validation error")
 case *json.SyntaxError, *json.UnmarshalTypeError:
 fmt.Println("The provided JSON input is invalid")
 // fmt.Println(err.Error()) 
 default:
 fmt.Println(err)
 }

Reference :

http://golang.org/pkg/encoding/json/#UnmarshalTypeError

Advertisement