I have reduced my situation to this play: Go Playground - The Go Programming Language - the interesting stuff starts on line 70. Take note of the input JSON. I’m essentially trying to traverse into the JSON structure enough to read those “type” fields so that I can do some custom unmarshaling.
My strategy is to get into that part of the structure, create a new decoder with the remaining bytes, then use it to decode into a generic map[string]interface{}
where I can then read the “type” field and use the first decoder to decode into a concrete type.
Calling Decode() on both decoders, in that loop, causes an error:
invalid character ‘,’ looking for beginning of value
So I thought I’d take this example from the Go docs and try to reproduce it even more minimally: Go Playground - The Go Programming Language (notice line 35) - and it works without errors. (This playground confirms that commas even exist there!)
Anyone know why this is?
(As a last resort, I’ve done my problem a different way where I create two decoders and they decode the entire structure in lock-step so they stay in the same spot as we go: Go Playground - The Go Programming Language - this works, but I kind of hate it.)