Standard library / encoding/json

encoding/json.Decoder.InputOffset()

Return the byte position at the end of the last token and beginning of the next. Useful for stream diagnostics, not a rune index. Expected stdout: '1\n'.

Formal Syntax & Structure

go syntaxgo
func (dec *Decoder) InputOffset() int64

Return Value

int64

Byte offset into the input stream.

Working Example

Example Snippetgo
package main
import (  "encoding/json"  "fmt"  "strings")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  d := json.NewDecoder(strings.NewReader("[1,2]"))  _, e := d.Token()  must(e)  fmt.Println(d.InputOffset())}
Go Reference