Standard library / encoding/json

encoding/json.UnsupportedValueError

Reports a value not supported by JSON, such as NaN, infinity or a cycle. Value and Str describe it. Expected stdout: 'true NaN\n'.

Formal Syntax & Structure

go syntaxgo
type UnsupportedValueError struct {  Value reflect.Value  Str   string}

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.NaN())  var x *json.UnsupportedValueError  fmt.Println(errors.As(e, &x), x.Str)}
Go Reference