ChimeraCoder / gojson

Automatically generate Go (golang) struct definitions from example JSON
GNU General Public License v3.0
2.67k stars 207 forks source link

Parse decimals ending in .0 as floats instead of ints #44

Open ChimeraCoder opened 8 years ago

ChimeraCoder commented 8 years ago
{
    "value": 10.0,
    "timestamp": 147847894,
}

value should be parsed as a float64, but timestamp should be an int64.

This comes from @nstogner: (https://github.com/ChimeraCoder/gojson/pull/22#issuecomment-248996855)

To elaborate on my personal use-case: I would like to be able to define a struct's default values via a JSON object... To do this I would like to use gojson to first create the struct and then use another process to read in the object again to determine the default values, ie:

{ "name": "", "health": "100", "score": 0.0 } -- piped thru gojson -->

type Foo struct {
Name string `json:"name"`
Health int `json:"health"` 
Score float64 `json:"score"` 
}

-- JSON object piped thru extra process -->

f := Foo{
Health: 100,
}

In other words, I would need to be able to support 0.0 values which get translated into floats.