I have a Json string that I want to unmarshal. This is working:
jsonString := []byte(`{"my_int": 3, "my_string": null}`)
var data map[string]interface{}
err := json.Unmarshal(jsonString, &data)
if err != nil {
fmt.Println(err)
}
//avroJson := make(map[string]interface{})
for k, v := range data {
fmt.Printf("%v, %T
", k, v)
}
My issue is: the value of my_int
which is 3 is returned as float64.
My question is: how to parse a json string with the "minimum type" so that 3
will return int32
and not the maximum type 3
=> float64
?
Assumption: my Json is huge and only have primitive types and I want a minimum value that is really float64 to continue to show float64
.
Clarification:
A "minimum type" means that if 3
can be considered both int32
and float64
the "minimum type" will be int32
, which is the exact type you'll get when running this:
reflect.TypeOf(3).string()