Go version

go1.25

Output of go env in your module/workspace:

n/a

What did you do?

Run this code:

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

Related Code Changes

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)