Standard library / encoding/json

encoding/json.UnsupportedValueError.Error()

Describe an unsupported value, such as NaN or infinity, even when its Go type is generally encodable. Expected stdout: 'true true\n'.

Formal Syntax & Structure

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

Return Value

string

Text representation or diagnostic.

Working Example

Example Snippetgo
package main
import (  "encoding/json"  "errors"  "fmt"  "math")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  _, e := json.Marshal(math.Inf(1))  var x *json.UnsupportedValueError  fmt.Println(errors.As(e, &x), len(x.Error()) > 0)}
Go Reference