Closed marcopaganini closed 5 years ago
Within an UnmarshalJSONArray
or UnmarshalJSONObject
don't use dec.DecodeObject
or dec.DecodeArray
but use dec.Object
or dec.Array
.
Example in your code:
func (x *areas) UnmarshalJSONArray(dec *gojay.Decoder) error {
err := dec.DecodeObject(x.areaRecord) // <----- replace by dec.Object(x.areaRecord)
fmt.Printf("Back from arearecord with %v, err = %v\n", x.areaRecord, err)
if err != nil {
return err
}
return nil
}
Excellent, that did the trick, thank you.
The documentation and examples section seem a bit light on the differences between dec.Add
dec.AddXXX
and dec.XXX
are basically the same (they parse keys/values inside objects/arrays) while dec.DecodeXXX
are top level methods (they decode a whole JSON). Yes I agree that documentation can be slightly reworked in that regard. I'd be very happy if you submit a PR :)
Thanks
Excellent, thanks. I'll certainly send you a few PRs. I'm closing this bug. Thanks again.
Hello,
I'm trying to parse a simple JSON file and somehow it always gives me an Invalid JSON message. Other parsers work fine. I'm unsure if this is a bug in gojay of if I'm doing something wrong.
I'm attaching a simple program that shows the problem: gojay.go.gz
The source is also available here for immediate viewing: https://repl.it/@marcopaganini/GojayUnableToParse
(Unfortunately, repl.it does not allow loading external libraries, so it's impossible to run it there).