Take a Look at https://blog.golang.org/json-and-go:
The json package uses map[string]interface{} and []interface{}values to store arbitrary JSON objects and arrays; it will happily unmarshal any valid JSON blob into a plain interface{} value. The default concrete Go types are: - bool for JSON booleans, - float64 for JSON numbers, - string for JSON strings, and - nil for JSON null. Does this help? 'Eric Johnson' via golang-nuts <golang-nuts@googlegroups.com> schrieb am Fr. 21. Feb. 2020 um 19:00: > If I've got a structure like this: > > type jsonData struct { > FirstName string `json:"first_name"` > LastName string `json:"last_name"` > } > > I can marshal / unmarshal JSON as: > { > "first_name": "first", > "last_name": "last" > } > > What if my input JSON is this: > { > "first_name": "first", > "last_name": "last", > "favorite_color": "orange", > "age": 92 > } > > Is there an existing library to have a structure that's something like > this: > > type jsonData struct { > FirstName string `json:"first_name"` > LastName string `json:"last_name"` > Extras map[string]interface{} `json:",extras"` > } > > Such that a JSON unmarshal and marshal will preserve the data of the > original JSON? > > I think I can probably make something work with the standard library, > except that it will require extra marshaling / unmarshaling steps that will > be annoying to reproduce for each structure that needs to capture extra > data. So I'm hoping there's a better solution? > > Eric > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/630827e2-8277-4231-9ab1-31881198a386%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/630827e2-8277-4231-9ab1-31881198a386%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CALWqRZqikwfQ9RJNUWtt3YKSkFcfFYFn9LadOzFEq7Gsfga7cA%40mail.gmail.com.