Standard library / encoding/json

encoding/json.InvalidUTF8Error

Deprecated historical error containing S, the offending string. Modern Marshal replaces invalid UTF-8 bytes with the replacement rune. Expected stdout: 'true true\n'.

Formal Syntax & Structure

go syntaxgo
type InvalidUTF8Error struct {  S string}

Working Example

Example Snippetgo
package main
import (  "encoding/json"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  b, e := json.Marshal(string([]byte{0xff}))  must(e)  var decoded string  must(json.Unmarshal(b, &decoded))  fmt.Println(decoded == "�", json.Valid(b))}
Go Reference