Hacker News new | ask | show | jobs
by xvello 1357 days ago
For that use case, I think that you can assign your defaults before passing your target struct to the unmarshaller.

The unmarshaller will iterate on the json input and set struct fields when json fields are found. This means that struct fields that don't match the json are ignored, and values you have set before will be left as is.

1 comments

While true, this approach doesn’t work for nested structs, which are instantiated by the parser.