RetroFed Forums
Your home away from modern life.
How can I prevent JSON from being unmarshaled into a field of a struct in Go?
Post Reply
AuthorMessage
Lena
gregtech.eu

lena@gregtech.eu
Joined: 2025-01-19
Posted:   Subject: How can I prevent JSON from being unmarshaled into a field of a struct in Go? Quote

cross-posted from: https://gregtech.eu/post/16712875

Marshaling the field is fine, so using the tag json:"-" won't work. I could use the UnmarshalJSON method on the struct, but I have no idea how to implement it.

I'd rather not make a duplicate of the struct with that field removed, as it causes quite a bit of code duplication, and it's pretty chaotic.

1   Original
Post Reply Page 1