Closed flowchartsman closed 1 year ago
I see the very same error message again with v0.4.2 and parsing {}
. Is my code wrong?
package main
import (
"fmt"
"github.com/minio/simdjson-go"
)
var raw = []byte(`{}`)
func main() {
json, err := simdjson.Parse(raw, nil)
if err != nil {
panic(err)
}
err = json.ForEach(func(it simdjson.Iter) error {
obj, _ := it.Object(nil)
return obj.ForEach(func(k []byte, _ simdjson.Iter) {
fmt.Println(string(k))
}, nil)
})
if err != nil {
panic(err)
}
}
Output:
panic: object: unexpected name tag }
goroutine 1 [running]:
main.main()
/tmp/sandbox90905901/prog.go:24 +0x68
Program exited.
@sdressler
It works on master. I will see if we can make a release.
// Parse JSON:
pj, err := Parse([]byte(`{}`), nil)
if err != nil {
log.Fatal(err)
}
// Create an element we can reuse.
err = pj.ForEach(func(i Iter) error {
fmt.Println("Got iterator for type:", i.Type())
obj, err := i.Object(nil)
if err == nil {
return obj.ForEach(func(k []byte, _ Iter) {
fmt.Println(string(k))
}, nil)
}
return nil
})
Outputs Got iterator for type: object
.
Released v0.4.3
Thanks! I failed to connect the dots between master & 0.4.2 release.
There appears to be a bug in
objectForEach
where the iterator over-reads the tape looking for a name or doesn't check for the object ending, maybe. Given the following example, which is an attempt to do array-transparent field iteration:The problem appears to be here in
parsed_object.go
wherein the advance fails if not finding a string, but not making an allowance for the end of the object, while the actual check for the end of the object occurs later, here. If I'm reading this right, it would throw an error on the (valid) JSON of an empty object:{}
.Maybe something like this?