You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
Perhaps we can't populate a specific structure without first reading the "type" field from the JSON. We could always do two passes over the decoding of the JSON (reading the "type" first, and the rest later).
However, it is much simpler to just decode this into a map[string]interface{} structure, read the "type" key, then use something like this library to decode it into the proper structure.
How would you go about this, if the JSON looks like this?:
In this case, each of the items in the animals array would adhere to the same interface (for example something that implements Name()) but each different type would correspond to a different struct type that implements said interface.
The README suggests that this is what mapstructure is practically made for, but I don't understand how to implement this.
The text was updated successfully, but these errors were encountered:
In the Buy Why?! section in the README is says:
How would you go about this, if the JSON looks like this?:
In this case, each of the items in the
animals
array would adhere to the same interface (for example something that implementsName()
) but each differenttype
would correspond to a different struct type that implements said interface.The README suggests that this is what
mapstructure
is practically made for, but I don't understand how to implement this.The text was updated successfully, but these errors were encountered: