Go version
go1.25
Output of go env
in your module/workspace:
n/a
What did you do?
package main
import (
"fmt"
"io"
"strings"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
)
func main() {
dec := jsontext.NewDecoder(strings.NewReader(`
"hello"
{}
[1,2,3]
`))
for {
var v any
if err := json.UnmarshalDecode(dec, &v); err != nil {
if err == io.EOF {
break
}
panic(err)
}
fmt.Println(v)
}
}
What did you see happen?
It should print:
hello
map[]
[1 2 3]
What did you expect to see?
Instead it prints:
hello
map[]
[1 2 3]
panic: jsontext: unexpected EOF after offset 27
This is a regression from https://go.dev/cl/689919
\cc @neild @jakebailey
Comment From: gopherbot
Change https://go.dev/cl/692175 mentions this issue: encoding/json/v2: fix UnmarshalDecode regression with EOF
Comment From: gabyhelp
Related Issues
- encoding/json: SyntaxError's Offset is wrong after decoding some valid json #32399 (closed)
- encoding/json: UnmarshalText confuses json.Unmarshal #8462 (closed)
- encoding/json: eof error of NewDecoder().Decode() should be same with Unmarshal() #25956
- encoding/json: unmarshal regression for extra data error under goexperiment.jsonv2 #74614 (closed)
- encoding/json/v2: change in Decoder.Token behavior at unexpected EOF #74750 (closed)
- encoding/json: misleading error for end-of-input in an escape sequence #58680
- encoding/json: Unintuitive behavior when using custom UnmarshalText #38947 (closed)
- proposal: encoding/json: option to clear output before unmarshal #49334 (closed)
- encoding/json: do not read beyond } in object #3942 (closed)
Related Code Changes
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)