[go-nuts] Re: Is overwriting contents of pointer field the expected behavior of json.Unmarshal?

2022-08-23 Thread Mateusz Wójcik
I'm aware of why the JSON unmarshal overwrites contents of the pointer, as I followed the code. I'm also aware of how to pass the slice argument "correctly". There's a problem with section (2) because that's not exactly what happens > during append. There was a proposition to re-initialize

[go-nuts] Re: Is overwriting contents of pointer field the expected behavior of json.Unmarshal?

2022-08-23 Thread Slawomir Pryczek
>From unmarshal doc: 1. To unmarshal JSON into a pointer, Unmarshal first handles the case of the JSON being the JSON literal null. In that case, Unmarshal sets the pointer to nil. Otherwise, Unmarshal unmarshals the JSON *into the value pointed at by the pointer*. *If the pointer is nil,

[go-nuts] Re: Is overwriting contents of pointer field the expected behavior of json.Unmarshal?

2022-08-22 Thread Tamás Gulácsi
"To unmarshal a JSON array into a slice, Unmarshal resets the slice length to zero and then appends each element to the slice." And you gave "" to Unmarshal twice. So it zeroed the length, and appended the second time, effectively overwriting the first (and only) element. This is intended