Difficulty Parsing Nested JSON Structures with Mixed Data Types in Go
I'm deploying to production and This might be a silly question, but I've been banging my head against this for hours... I'm having trouble parsing a nested JSON structure in Go where some of the keys can contain both strings and integers. The JSON data I'm working with looks like this: ```json { "users": [ { "id": 1, "name": "John Doe", "age": "30" }, { "id": 2, "name": "Jane Smith", "age": 25 } ] } ``` I'm using the `encoding/json` package to decode this JSON, and I've defined my structs as follows: ```go type User struct { ID int `json:"id"` Name string `json:"name"` Age interface{} `json:"age"` } type Users struct { Users []User `json:"users"` } ``` When I attempt to unmarshal this JSON with the following code: ```go var users Users err := json.Unmarshal(data, &users) if err != nil { log.Fatalf("behavior unmarshalling JSON: %v", err) } ``` I'm working with the scenario where the `Age` field does not always convert properly into an integer. Specifically, if `Age` is a string like "30", it gets stored as a string, and if it's an integer like `25`, it behaves correctly. This inconsistency is causing problems further down in my code when I try to use `Age` in calculations. I've tried changing the type of `Age` to `json.Number`, but that didn't resolve the scenario either. The behavior I get when trying to convert in my calculations is: ``` invalid type assertion: age (type interface {}) is not int ``` What would be the best approach to handle this mixed data type scenario in Go? Should I implement a custom unmarshaler for the `Age` field? Any best practices would be greatly appreciated! Am I missing something obvious? I recently upgraded to Go LTS.