Standard library / encoding/json

encoding/json.SyntaxError.Error()

Return the diagnostic message for invalid JSON syntax. Offset identifies a byte position; do not parse the human-readable message as a stable protocol. Expected stdout: 'true true\n'.

Formal Syntax & Structure

go syntaxgo
func (e *SyntaxError) 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 v any  e := json.Unmarshal([]byte("[}"), &v)  var x *json.SyntaxError  fmt.Println(errors.As(e, &x), len(x.Error()) > 0)}
Go Reference