Standard library / encoding/json
encoding/json.SyntaxError
Reports invalid JSON syntax. Offset counts bytes read when the error occurred; Error provides a diagnostic message. Expected stdout: 'true 2\n'.
Formal Syntax & Structure
go syntaxgo
type SyntaxError struct { Offset int64 // Has unexported fields.}Working Example
Example Snippetgo
package main
import ( "encoding/json" "errors" "fmt")
func must(e error) { if e != nil { panic(e) }}
func main() { var x any e := json.Unmarshal([]byte("[}"), &x) var s *json.SyntaxError fmt.Println(errors.As(e, &s), s.Offset)}