Standard library / encoding/json

encoding/json.UnmarshalTypeError.Error()

Describe a JSON value incompatible with the Go destination type. Inspect structured fields for programmatic diagnostics. Expected stdout: 'true true\n'.

Formal Syntax & Structure

go syntaxgo
func (e *UnmarshalTypeError) Error() string

Return Value

string

Text representation or diagnostic.

Working Example

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