[Solved] Why is unmarshaling into a pointer variable not possible?


Why is unmarshaling into a pointer variable not possible?

It is possible. In fact, it’s required. Unmarshaling to a non-pointer is not possible.

json: Unmarshal(nil *main.configuration)

This error isn’t saying you can’t unmarshal to a pointer, it’s saying you can’t unmarshal to a nil pointer. The pointer must point to a valid (probably zero-value) variable.

Replace

var config *configuration

With

config := new(configuration)

or

config := &configuration{}

and it should work just fine.

solved Why is unmarshaling into a pointer variable not possible?